Skip to content
shellhacks.dev
Linux

How the Linux File System Is Laid Out and What Lives Where

A tour of the top level Linux folders, from bin and etc to var and tmp, with what belongs in each and the commands to look inside safely.

5 min read
Summarize in AI
Illustration for "How the Linux File System Is Laid Out and What Lives Where": a terminal session, file permission bits, a directory tree.

Windows users look for C: and find nothing. Linux has a single tree that begins at /, and every disk, USB stick and network share appears somewhere inside it. Knowing what each top-level folder is for tells you where to look for a config file, a log, or the 40 GB that filled the disk. The formal rules are covered in the Linux filesystem hierarchy standard; this post is a tour. It is a subtopic of the Linux command line every developer needs.

The layout described is that of Debian 13 and Ubuntu 24.04. Fedora and Arch differ in small ways, noted where they matter.

Look for yourself

Shell
ls /

On a typical Debian system the output includes bin, boot, dev, etc, home, lib, media, mnt, opt, proc, root, run, sbin, srv, sys, tmp, usr and var. Here is what they are for.

The ones you will use

DirectoryHoldsExample
/etcSystem-wide configuration, as text files/etc/ssh/sshd_config, /etc/fstab
/homeOne folder per user/home/alex/.bashrc
/varData that changes: logs, caches, spools, databases/var/log, /var/lib/docker
/usrInstalled programs, libraries, docs/usr/bin/python3
/tmpScratch space, cleared at boot on many systemsTemporary files
/optSelf-contained third-party softwareVendor installers
/srvData served by this machineWeb or FTP content, by local convention

The ones that are not on disk

/proc and /sys are virtual: the kernel builds their contents on demand. cat /proc/cpuinfo and cat /proc/meminfo read live information, and /proc/PID has one folder per running process. /dev holds device nodes; /dev/null discards what is written to it, and /dev/sda or /dev/nvme0n1 are disks. /run is a memory-backed folder for runtime state such as PID files and sockets. Because none of these use disk space, they never appear in a hunt for what is filling the disk, though du will happily walk into them unless you tell it not to.

The ones that sound the same

  • /bin, /sbin, /lib: on modern Debian, Ubuntu, Fedora and Arch these are symbolic links to /usr/bin, /usr/sbin and /usr/lib. The "usr merge" made all programs live under /usr. Check with ls -ld /bin.
  • /usr/local: for software you install yourself, kept apart from the package manager's files.
  • /mnt and /media: places to mount other filesystems, the first by hand and the second by desktop automounting.
  • /boot: the kernel and boot loader files. Do not delete old kernels by hand; use the package manager.

Where the space goes

When a disk fills, the usual suspects are /var/log (logs), /var/lib (databases, container images) and /home (user data). sudo du -xh --max-depth=1 /var | sort -h ranks them, and the -x flag keeps du on one filesystem so it skips /proc. The full procedure is in how to find what is using disk space on Linux.

Reading the top level on a real system

Here is the listing from a Debian 13 container. A full desktop or server has a few more entries, such as lost+found on a volume formatted with ext4, and the order is alphabetical.

Shell
ls /
ls -ld /bin /usr/bin /var/run
Text
bin   dev   home  media  opt   root  sbin  sys  usr
boot  etc   lib   mnt    proc  run   srv   tmp  var
lrwxrwxrwx 1 root root    7 Jul 17 17:05 /bin -> usr/bin
drwxr-xr-x 1 root root 4096 Oct 28 01:33 /usr/bin
lrwxrwxrwx 1 root root    4 Oct 27 00:00 /var/run -> /run

Two details deserve attention. On this system /bin is a symbolic link to /usr/bin, which is the result of the usr merge explained in the next post, so the directory you think of as holding the essential commands is a pointer. And /var/run is a link to /run, the memory-backed directory where running programs keep their sockets and process ID files. The permissions on both links read rwxrwxrwx because a link's own mode is ignored; the target's mode is what counts.

Some directories are not files at all

The contents of /proc and /sys are produced by the kernel when you read them. There is no disk behind them. That makes them useful as an interface: reading a file asks the kernel a question.

Shell
grep -c ^processor /proc/cpuinfo
head -n 1 /proc/meminfo
cat /proc/self/comm
Text
10
MemTotal:       13262928 kB
cat

The first command counted logical CPUs, the second read the total memory the kernel sees, and the third printed the name of the process doing the reading, which was cat. Nothing was stored; every read produced fresh data. The same applies to /dev, where files such as /dev/null and /dev/urandom stand for devices handled in the kernel. Do not copy these directories in a backup, and do not expect their sizes to mean anything.

Where to put your own files

Use your home directory for personal work. For software you build and install yourself, /usr/local is the conventional place, because package managers leave it alone. Optional large packages that bring their own directory tree go under /opt. Data a service serves, such as a website or a repository, belongs under /srv or the service's own directory in /var/lib. Files that change constantly, including logs and caches, live in /var, which is why it is the directory that fills a disk. Putting your own scripts in /usr/bin mixes them with files the package manager owns, and an upgrade may delete or replace them without warning.

Which directories to leave alone

Some of what you see at the top level is not yours to change. Do not edit anything under /proc, /sys or /dev unless you know the exact effect, because writing to those files reaches into the running kernel. Leave /usr and /lib to the package manager, since files placed there by hand are overwritten by the next upgrade or confuse it. Be careful with /boot, where a wrong edit can make the machine unbootable. The directories that are safe for your own work are your home directory, /tmp for short-lived files and /srv or /opt for software you install yourself.

Before you delete anything outside your home, look at what owns it: dpkg -S /path on Debian or rpm -qf /path on Red Hat systems says which package a file belongs to, and a file that belongs to a package should be removed with the package.

Where this picture is incomplete

The tree is the same everywhere, but what is mounted where is not. Containers have their own trees, NixOS puts programs in /nix/store, and macOS uses a different layout entirely. The Filesystem Hierarchy Standard is the source for the conventions, and man hier or hier(7) describes the layout of your own system.

Share

Keep reading

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.