The filesystem hierarchy

Linux · Essentials · 8 min

Knowing the standard layout means you can find any config file or log on a machine you have never seen.

Linux has a single directory tree starting at / (the root). There are no drive letters: other disks are mounted at directories inside the tree. The layout follows the Filesystem Hierarchy Standard:

  • /etc: system-wide configuration (text files),
  • /var: variable data such as logs (/var/log), caches, spools and databases (/var/lib),
  • /home/<user>: users' files; /root is root's home,
  • /usr: installed programs and libraries (/usr/bin, /usr/lib); /usr/local for software you install by hand; on modern distributions /bin and /lib are just symlinks into /usr,
  • /opt: self-contained third-party applications,
  • /tmp: temporary files, often cleaned at boot and sometimes stored in RAM,
  • /boot: the kernel and bootloader files,
  • /dev: device files such as disks (/dev/sda, /dev/nvme0n1) and /dev/null,
  • /proc and /sys: virtual filesystems where the kernel exposes processes and hardware as files,
  • /run: runtime state such as PID files and sockets, cleared at boot,
  • /mnt and /media: mount points for extra or removable disks.

The Unix idea that "everything is a file" shows up everywhere: devices, process information and kernel settings are all read and written with ordinary file tools.

Example

ls /
# bin boot dev etc home lib media mnt opt proc root run srv sys tmp usr var
ls -ld /bin                 # lrwxrwxrwx ... /bin -> usr/bin   (merged /usr)
ls /etc | head -n 3         # system-wide configuration files
ls /var/log | head -n 3     # log files
cat /proc/loadavg           # kernel data presented as a file
ls -l /dev/null             # crw-rw-rw- ... /dev/null   (c = character device)
echo ~ "$HOME"              # /home/ada /home/ada

Remember

  • One tree from /; other disks are mounted into it
  • Config in /etc, logs and data in /var, programs in /usr
  • /proc, /sys and /dev expose the kernel and devices as files

Watch out for

  • Storing application data in /tmp, which may be wiped at reboot.

Check yourself

  1. Where would you look first for a service's log files written to disk?
  2. What is special about /proc?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: man7.org/linux/man-pages/man7/hier.7.html