I accidentally removed my ~/bin directory. I have seen plenty of questions asking what to do if /usr/bin is removed, and that situation seems to be much more serious. What can I do to reconstruct the folder?
~/bin is for user's own scripts and executables. It's not system-critical and not specified by any standard, unlike /usr/bin. To quote Debian documentation:
/bin/
Essential command executable (binaries) for all users (e.g., cat, ls, cp)
(especially files required to boot or rescue the system)
...
/usr/
Secondary hierarchy for shareable, read-only data (formerly from UNIX source repository, now from UNIX system resources)
(files that are not-required to boot or rescue the system)
The directory is added to user's PATH variable (which is what is referenced when you call commands by name instead of full pathname, e.g. bash vs /bin/bash). The purpose is to allow user call their own private scripts and executables by name. Specifically, that's handled in ~/.profile:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
The ~/.profile is read and executed ( and therefore the directory is added ) when the shell is used as login shell or according to geirha's answer when logging into GNOME-based desktop.
Mostly, what it contains is defined by the users themselves. It is quite possible that 3rd party software could place scripts there, though I've not come across such cases yet.
What to do about the deleted ~/bin ?
As mentioned before, the directory is not system critical. Unless you yourself placed something system-significant there (which is probably a bad idea and not practical), it could cause issues within the scope of what was actually done. Otherwise, there's essentially no effect, just like when you remove any other non-critical directory. If it was empty or you have backup of files it contained, there's no need to do anything else. You can recreate it either via file manager or command-line with mkdir ~/bin.
What is ~/bin and why does it exist ?
~/bin
is for user's own scripts and executables. It's not system-critical and not specified by any standard, unlike/usr/bin
. To quote Debian documentation:See also Categorize the File Hierarchy System.
The directory is added to user's
PATH
variable (which is what is referenced when you call commands by name instead of full pathname, e.g.bash
vs/bin/bash
). The purpose is to allow user call their own private scripts and executables by name. Specifically, that's handled in~/.profile
:The
~/.profile
is read and executed ( and therefore the directory is added ) when the shell is used as login shell or according to geirha's answer when logging into GNOME-based desktop.Mostly, what it contains is defined by the users themselves. It is quite possible that 3rd party software could place scripts there, though I've not come across such cases yet.
What to do about the deleted ~/bin ?
As mentioned before, the directory is not system critical. Unless you yourself placed something system-significant there (which is probably a bad idea and not practical), it could cause issues within the scope of what was actually done. Otherwise, there's essentially no effect, just like when you remove any other non-critical directory. If it was empty or you have backup of files it contained, there's no need to do anything else. You can recreate it either via file manager or command-line with
mkdir ~/bin
.If you had your own scripts/programs there, you could try recovering them. See How to recover deleted files?, Tool for recovering deleted data from a flash drive, and Unix/Linux undelete/recover deleted files. There are multiple selections of utilities. Note, that it is assumed you have default ext4 filesystem. In case you have something else, the filesystem may have its own specific utilities for recovering files, such as for btrfs. For future, you can consider doing backups of the directories and files. See What's a good back-up strategy for 1 desktop PC?