Skip to content
Tutorials Center
My learning

Topics

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.

  • /usr holds 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/local is 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.
  • /opt holds self-contained add-on packages, each in its own folder such as /opt/google/chrome, with their own bin and lib.
Terminal
echo "$PATH"
ls /usr /usr/local
sudo install -m 755 mytool /usr/local/bin/mytool

Try it

Bash Where do commands come from?

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.

Bash Your own tool in a local prefix

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 on PATH.
  • PATH order matters. Debian-style systems list /usr/local/bin before /usr/bin, so a local python shadows the packaged one. which -a name shows all matches.
  • make install defaults to /usr/local. Override with ./configure --prefix=$HOME/.local to avoid sudo.
  • Do not edit /usr by hand. Changes are lost or cause package conflicts on the next update. Use dpkg -S file or rpm -qf file to 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/doc often has examples and licenses for installed packages.