Linux Command Reference ยท Special Files and Directories
The /usr, /opt and /usr/local directories
Reference for /usr, /opt and /usr/local: what each tree holds, how bin and sbin differ, the usr-merge, where to install your own programs, and how PATH finds them.
Installed software on Linux is spread over a few well-known trees, and which one a file lives in tells you who put it there.
/usrholds the bulk of the operating system's programs, libraries and documentation, installed by the package manager. Despite the name it is not "user data"; it is mostly read-only during normal operation./usr/localis reserved for software you install by hand (make install, your own scripts). The package manager never touches it, so updates will not overwrite your files./optholds self-contained add-on packages, each in its own folder such as/opt/google/chrome, with their ownbinandlib.
echo "$PATH" ls /usr /usr/local sudo install -m 755 mytool /usr/local/bin/mytool
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
| Path | Contents |
|---|---|
/usr/bin |
Ordinary commands from packages. |
/usr/sbin |
Administration commands (often for root). |
/usr/lib, /usr/lib64 |
Libraries and helper programs. |
/usr/share |
Architecture-independent data: docs, man pages, icons, locales. |
/usr/include |
C and C++ header files. |
/usr/src |
Kernel and other source code. |
/usr/local/{bin,lib,share,etc} |
Same layout, for locally installed software. |
/opt/PACKAGE/ |
A bundled application tree. |
Edge cases: on modern distributions the usr-merge makes /bin, /sbin and /lib symbolic links to /usr/bin, /usr/sbin and /usr/lib, so both paths reach the same file. Older systems keep them separate.
Usage notes
- Choosing a place: package manager owns
/usr; you own/usr/local; vendors who ship a self-contained bundle use/opt. For single users,~/.local/bin(and~/bin) needs no root and is often already onPATH. - PATH order matters. Debian-style systems list
/usr/local/binbefore/usr/bin, so a localpythonshadows the packaged one.which -a nameshows all matches. make installdefaults to/usr/local. Override with./configure --prefix=$HOME/.localto avoid sudo.- Do not edit
/usrby hand. Changes are lost or cause package conflicts on the next update. Usedpkg -S fileorrpm -qf fileto see which package owns a file. - Read-only
/usr: some systems (immutable distributions, containers) mount it read-only; add software with Flatpak, containers or~/.local. /usr/share/docoften has examples and licenses for installed packages.
Related
which,type,whereis,install,make- Lessons: Filesystem layout, Compiling from source, Environment