Unix systems have a number of traditions and conventions for what goes where in the filesystem. Linux follows Unix.
A Unix system has directories such as /bin
and /usr/bin
for
executables, and the difference may be a bit mysterious. It gets
worse, though, once you realise there is at least six other
directories for executables: /sbin
, /usr/sbin
, /usr/local/bin
,
/usr/local/sbin
.
In addition to its binaries, a program may consist of data files, shared libraries, and documention, and it may need to write various files for different purposes. The Unix tradition is to spread these into different areas of the filesystem tree.
Some other operating systems have a different approach, often one where all the parts of a program are put in the same place. Unix instead combines like with like: executables in one place (or six), documentation in another, and data files in a third. A common justification is that, say, backing up only the data files becomes easier: everything else can just be reinstalled, if need be.
Early on in the history of Linux, there were big differences between where different Linux distributions put files. A consensus grew that a standard would be beneficial, and so FSSTND, the Linux file system standard, was born. Some years later, its scope was broadened to all free software implementations of Unix and it got renamed to FHS.
The FHS Wikipedia page gives an overview. The actual standard is quite readable and is recommended for when you have time. Additionally the hier(7) also gives an overview. We refer you to those rather than writing our own summary
Things in the filesystem standards world change. The directory tree is alive. For example:
/var/run
(runtime information, cleared on boot) is moving to/run
since keeping it in/var
doesn't make anything better.Historically the Unix directory tree is split across two or more disks. The root disks has
/etc
, and/bin
and more. A second disk is mounted as/usr
and contains/usr/bin
among other things. This is getting changed so that the directories with static data on the root disk get moved to/usr
and replaced with symlinks (e.g.,/bin -> /usr/bin
). After that, the root disk only has a minimal amount of variable data, such as/etc
. Thus, almost the entire operating system is on a read-only disk, which has benefits for reliability, and can allow sharing it between, say, virtual machines or containers.This seems to a remarkably controversial change. Change is scary.
How did the Unix directory tree grow into the sprawling ent that it is today? It happened mostly through incremental change, not by design. You could almost say it happened organically.
For example, the /usr
directory was originally, in the early 1970s,
meant for home directories. "Usr" is short for "user" in various
parts of Unix. What happened was the the Unix developers had two disks
in their machine, one for the system, the other for user home
directories. They ran out of disk space on the system disk, and fixed
this by moving parts of the system to the user disk, eventually
crowding out users from /usr
to /home
. As a result we now have the
system spread on the "root disk", and the "user disk" (/usr
).