In Linux the different locations usually, when well maintained, mirror some logic. Eg.:
/bin
contains the most basic tools (programs)
/sbin
contains the most basic admin programs
Both of them contain the elementary commands used by booting and fundamental troubleshooting. And here you see the first difference. Some programs are not meant to be used by regular users.
Then take a look in /usr/bin
. Here you should find a bigger choice of commands (programs), usually more than 1000 of them. They are standard tools, but not as essential as those in /bin
and /sbin
.
/usr/bin
contains the commands, while the configuration files reside elsewhere. This both separates the functional entities (programs) and their config and other files, but in terms of user functionality, this comes handy, as having the commands not intermixed with anything else allows for the simple use of the PATH
variable pointing to the executables. It also introduces clarity. Whatever is should be executable.
Take a look at my PATH
,
$ echo "$PATH" | perl -F: -anlE'$,="\n"; say @F'
/home/tomas/bin
/usr/local/bin
/usr/bin
/bin
/usr/local/games
/usr/games
There are exactly six locations containing the commands I can call directly (ie. not by their paths, but by their executables' names).
/home/tomas/bin
is my private directory in my home folder for my private executables.
/usr/local/bin
I'll explain separately below.
/usr/bin
is described above.
/bin
is also described above.
/usr/local/games
is a combination of /usr/local
(to be explained below) and games
/usr/games
are games. Not to be mixed with utility executables, they have their separate locations.
Now to /usr/local/bin
. This one is somewhat slippery, and was already explained here: What is /usr/local/bin?. To understand it, you need to know that the folder /usr
might be shared by many machines and mounted from a net location. The commands there are not needed at bootup, as noted before, unlike those in /bin
, so the location can be mounted in later stages of the bootup process. It can also be mounted in a read-only fashion. /usr/local/bin
, on the other hand, is for the locally installed programs, and needs to be writable. So while many network machines might share the general /usr
directory, each one of them will have their own /usr/local
mounted inside the common /usr
.
Finally, take a look at the PATH
of my root user:
# echo "$PATH" | perl -F: -anlE'$,="\n"; say @F'
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
It contains these:
/usr/local/sbin
, which contains the admin commands of the type /usr/local
/usr/local/bin
, which are the same ones the regular user can use. Again, their type can be described as /usr/local
.
/usr/sbin
are the non-essential administration utilities.
/usr/bin
are the non-essential administration and regular user utilities.
/sbin
are the essential admin tools.
/bin
are the admin and regular user essential tools.
noexec
flag; keep the binaries and libraries on filesystems with block-level cryptographic signatures; etc). – Charles Duffy Mar 17 '18 at 20:51/Programs/
which may be more similar to Windows – phuclv Mar 18 '18 at 06:45/lib
used by many programs in/bin
. Also because of PATH (finding programs). However sometime the other way is better. Then we use/opt
with one sub-directory per package. Or my usingstow
to manage/usr/local/…
for you. – ctrl-alt-delor Mar 18 '18 at 17:47