4

Do binaries from this get source immediately?

Do I need to add it to bash profile to be sourced?

If I understand correctly, there are other places for binaries like:

  • /usr/bin
  • /bin
  • /usr/local/bin

Why so many?

2
  • 2
    Did you mean /home/username/bin (also written as $HOME/bin) instead of /home/bin?
    – marcelm
    May 14 at 16:20
  • I have too little quality points to post it as a comment, so: @Terrance has answered the question but the following link adds to the 'why so many' part: lists.busybox.net/pipermail/busybox/2010-December/074114.html tldr; there is no need for so many. They are leftovers from hardware limitations from half a century ago. May 15 at 0:57

2 Answers 2

10

The bin folders are used for executable programs.

Before Ubuntu 19.10 the folder of /bin itself was used for minimal functionality for the purposes of booting and repairing a system. The /usr/bin folder was used for most of the executable programs. Now /bin is symlinked to /usr/bin so they are now one and the same.

$ lsb_release -r
Release:    20.04
$ ls -al /
total 104
drwxr-xr-x  20 root root  4096 Apr 16 08:28 .
drwxr-xr-x  20 root root  4096 Apr 16 08:28 ..
lrwxrwxrwx   1 root root     7 Oct  2  2021 bin -> usr/bin
$ lsb_release -r
Release:    18.04
$ ls -al /
total 1459924
drwxr-xr-x  24 root root       4096 Feb 24 07:36 .
drwxr-xr-x  24 root root       4096 Feb 24 07:36 ..
drwxr-xr-x   2 root root       4096 Feb 24 07:11 bin

The /usr/local/bin is used for executable programs that are not managed by a distribution package.

The answer for your $HOME/bin folder is contained in the .profile in your home folder (/home/<user>/). It (.profile) is sourced automatically when you log in.

Contained in the .profile file in your home folder are the following sections (It is all about preference):

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"

If either of those bin folders exist they are automatically added to the $PATH when the user logs into their account. It is used for the user's own private executable programs and scripts. They are primarily used for the user or owner of those folders, keeping them private from other users.

5
  • 2
    Just to add to this, because the directory is automatically added to the PATH when you log in, if and only if it exists, it is not immediately added when the directory is initially created. So you have to log out and log back in after this directory is initially created.
    – mchid
    May 14 at 4:41
  • 1
    Nothing there seems to indicate that scripts in the directory are sourced when you log in (which I wouldn't expect). You might also want to note that you are discussing /home/<user>/bin, not /home/bin as in the question. May 14 at 14:12
  • 1
    If your ubuntu was installed as 19.04 or later, /usr and /usr/bin are symlinked by default, so there is no difference between them: reddit.com/r/linux/comments/9x3f0k/… May 14 at 22:35
  • @user1937198 Good point. Updated answer. =)
    – Terrance
    May 14 at 23:28
  • ~/.profile gets sourced by the shell. This is compiled into the shell program. Different shells look for other default files, so this answer assumes sh, bash, or a compatible shell of that type.
    – JohnP
    May 16 at 21:24
1

Linux systems are multiuser, even if there is only 1 person using the system. That's worth remembering.

  • /bin was for programs necessary in a minimal environment, no GUI.
  • /usr/bin is for optional programs, but commonly used programs with or without a GUI.
  • /usr/local/bin is for programs that aren't managed by the package manager. This would typically be scripts or custom code or custom compiled code for all users of the system to have access
  • ~/bin/ is for scripts, code, custom code that are for a single user, not everyone. It is also a place that a user can put any code they like if the system admin refuses to install a package or install a non-packaged program into /usr/local.

The major Linux distros follow (mostly) the Linux File System Hierarchy Standards document. A summary of what each directory is for can be found in the wikipedia article by that name. https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard It closely follows the UNIX File System Hierarchy Standards that has been around 30+ yrs. I don't know if UNIX standards are truly standard, but they all seem to be very similar.

The only place that I see where those standards are violated on Ubuntu (and some other distros) is related to /media/ and where ever snap packages go. But that's a different question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy