There are variations, but also common themes and well-established guidelines.
root
(/) hierarchy:
Directory | Description |
---|---|
bin |
Essential command binaries (e.g. ls, rm, chmod, perl, bash…) |
boot |
Static files of the boot loader |
dev |
Device files (e.g. console, null, tty, stdin/out/err) |
etc |
Host-specific system configuration (e.g. hosts, fstab) |
lib |
Essential shared libraries and kernel modules |
media |
Mount point for removeable media |
mnt |
Mount point for mounting a filesystem temporarily |
opt |
Add-on application software packages |
sbin |
Essential system binaries (e.g. fdisk, fsck) |
srv |
Data for services provided by this system |
tmp |
Temporary files |
usr |
Secondary hierarchy |
var |
Variable data (e.g. mail) |
Another example:
usr
hierarchy:
Directory | Description |
---|---|
bin |
Most user commands (usually installed by package manager) |
include |
Header files included by C programs |
lib |
Libraries |
local |
Local hierarchy (empty after main installation) |
sbin |
Non-vital system binaries |
share |
Architecture-independent data |
/usr/local
hierarchy:
Directory | Description |
---|---|
bin |
Local binaries (not installed by package manager - eg. compiled) |
etc |
Host-specific system configuration for local binaries |
games |
Local game binaries |
include |
Local C header files |
lib |
Local libraries |
man |
Local online manuals |
sbin |
Local system binaries |
share |
Local architecture-independent hierarchy |
src |
Local source code |
Broadly speaking…
By convention, software compiled and installed manually (not through a package manager, e.g apt, yum, pacman) is installed in /usr/local/
.
If you just need to extract a tarball and run directly (e.g. Firefox) then put it into /opt/
.
https://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux
(1) /bin/
(2) /sbin/
(3) /usr/bin/
(4) /usr/local/bin/
(5) /usr/local/sbin/
/bin
(and /sbin
) were intended for programs that needed to be on a small /
partition before the larger /usr
, etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like /bin/sh
, although the original intent may still be relevant for e.g. installations on small embedded devices./sbin
, as distinct from /bin
, is for system management programs (not normally used by ordinary users) needed before /usr
is mounted./usr/bin
is for distribution-managed normal user programs./usr/sbin
with the same relationship to /usr/bin
as /sbin
has to /bin
./usr/local/bin
is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into /usr/bin
because future distribution upgrades may modify or delete them without warning./usr/local/sbin
, as you can probably guess at this point, is to /usr/local/bin
as /usr/sbin
to /usr/bin
.In addition, there is also /opt
which is for monolithic non-distribution packages, although before they were properly integrated various distributions put Gnome and KDE there. Generally you should reserve it for large, poorly behaved third party packages such as Oracle.
Run the man hier
command to see what you have.
A diagram from here: