Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Linux directory tree: what each directory is for

By updated

Improve this page

A configuration file vanished after an update, a service writes its logs somewhere unexpected, a /var disk is full for no obvious reason: these situations come up often in Linux administration. The answer is almost always the same: know where Linux keeps each type of file.

The Filesystem Hierarchy Standard (FHS) is the convention that defines what each main directory is for: configuration, logs, programs, user data. When you know these directories, you know where to look for a file.

What you will learn

  • Identify the role of each functional area of the tree (/etc/, /var/, /usr/, /run/…)
  • Know where to look for configuration, logs, binaries and runtime data
  • Tell apart the differences between distributions (Debian/Ubuntu, RHEL/Rocky, Alpine)
  • Diagnose a problem by targeting the right directory
  • Avoid the usual file placement mistakes

Two pages cover the FHS, and they do not do the same thing. The Linux fundamentals guide gives the overview: the annotated tree, three administration reflexes, a short lab. This one goes into the detail of each area, with the commands to check it and the administration cases attached to it.

Where should you look? The admin reflex

Before going into detail, here is a table that tells you where to look. Read it from left to right: what you are looking for, the directory that holds it, and the quick command that confirms it.

You are looking for…Look in…Quick command
The configuration of a service/etc/ls /etc/<service>/
The logs of a service/var/log/ or journalctljournalctl -xeu <service>
A binary or a command/usr/bin/, /usr/sbin/which <command>
The runtime state (PID, socket)/run/ls /run/<service>/
The persistent data of a service/var/lib/ls /var/lib/<service>/
A temporary file/tmp/ or /var/tmp/ls /tmp/
A user's files/home/<user>/ls -la /home/<user>/
The boot files/boot/ls /boot/
A device (disk, partition)/dev/lsblk

What does each area of the FHS contain?

The FHS sorts files by two criteria: can they be shared between machines, and can they change while the system runs. That classification explains why some directories look redundant at first sight.

/etc/: the system configuration

You will come back to this directory often. Every installed service drops its configuration there, as text files you can edit.

Common subdirectories:

PathContents
/etc/ssh/SSH server and client configuration (sshd_config, host keys)
/etc/systemd/Local overrides of systemd units
/etc/apt/ or /etc/yum.repos.d/Package sources (Debian/Ubuntu or RHEL/Rocky)
/etc/netplan/ or /etc/NetworkManager/Persistent network configuration
/etc/fstabTable of persistent mounts
/etc/passwd, /etc/shadow, /etc/groupUser accounts and groups
/etc/sudoers, /etc/sudoers.d/Privilege delegation rules
/etc/logrotate.d/Log rotation rules
/etc/crontab, /etc/cron.d/System scheduled tasks
Terminal window
# List the subdirectories of /etc to see which services are configured
ls -d /etc/*/

For systemd units, one rule applies: never edit a file in /usr/lib/systemd/. That path belongs to the package manager, which rewrites its contents on the next update and wipes your changes without warning. Copy the file into /etc/systemd/system/ to create a local override: it takes precedence over the package file and survives updates.

Related guides: Users and groups, sudo, Persistent mounts, systemd.

/var/: variable data

/var/ stores everything that changes over time: logs, caches, queues, and the databases of services. Each subdirectory has its own rule about what you may clean.

PathContentsWhy it matters
/var/log/System and application logsFirst place to check during an incident
/var/lib/Persistent state of services (databases, packages)Do not delete without understanding
/var/cache/Package manager cachesCan be cleaned to recover space
/var/spool/Queues (printing, mail, cron)Rarely edited by hand
/var/tmp/Temporary files kept across rebootsMore durable than /tmp/

Focus: /var/log/, the logs

Logs help you diagnose an incident. It is the file names that vary with the distribution: the same information lives in different files on Debian and on RHEL. On Debian, rsyslog has no longer been installed by default since Debian 12 (Debian 12 release notes): system messages are therefore read with journalctl.

Without the rsyslog package, the files /var/log/syslog, /var/log/auth.log and /var/log/kern.log do not appear, and system messages are read with journalctl. If you install rsyslog, these three files are created.

FileContents
/var/log/journal/systemd binary journal, read with journalctl
/var/log/dpkg.logAPT installs and updates
/var/log/apt/History and output of APT commands
/var/log/syslogGeneral system messages (with rsyslog only)
/var/log/auth.logLogins, authentication, sudo (with rsyslog only)
/var/log/kern.logKernel messages (with rsyslog only)
/var/log/apache2/Apache logs (if installed)

Logs keep growing, and that has a consequence worth anticipating: on a production server, if /var/ shares the partition (a portion of the disk) of /, a full disk blocks the whole system, not only logging. Hence the common practice of putting /var/ on a separate partition, and the monitoring reflex that goes with it, df -h /var.

Terminal window
# See how much space the logs take
du -sh /var/log/
# Check the space left on the partition
df -h /var
# Read the latest system journal entries
journalctl -n 50 --no-pager

Related guides: Logs with journalctl, Rotation with logrotate and Monitor disk space.

/usr/: binaries, libraries and documentation

/usr/ holds most of the programs and libraries installed by the package manager. Its contents only change when you install or update packages.

PathContents
/usr/bin/User commands (ls, grep, systemctl, vim…)
/usr/sbin/Administration commands (fdisk, useradd, iptables…)
/usr/lib/Shared libraries (.so) and support files
/usr/lib/systemd/systemd units shipped by packages (do not edit here)
/usr/share/Documentation, architecture-independent files
/usr/local/Software installed by hand (outside the package manager)

A bit of history explains what you will see on a recent machine. /bin/ and /sbin/ used to be separate directories, reserved for the binaries needed to boot. On Debian 12+, Ubuntu 22.04+, RHEL 9+, Fedora and Arch, they are now symbolic links to /usr/bin/ and /usr/sbin/, that is, shortcuts that point to another location (the guide Hard and symbolic links covers them in detail). This is the merge known as usr-merge. In practice, ls /bin and ls /usr/bin show the same contents.

The merge actually covers 4 directories, not two: /lib/ and /lib64/ are also links to usr/lib/ and usr/lib64/. A second, more discreet wave targeted /var: /var/run and /var/lock now point to /run and /run/lock. Knowing this avoids a common confusion, because you still come across /var/run/something.pid in plenty of scripts and documentation: those paths still work, but no longer designate the place you think.

The loop below establishes the real state of your machine in one go:

Terminal window
for d in /bin /sbin /lib /lib64 /var/run /var/lock; do
printf '%-11s -> %s\n' "$d" "$(readlink "$d" || echo '(not a link)')"
done

On an Ubuntu 24.04 machine, all six entries are links:

/bin -> usr/bin
/sbin -> usr/sbin
/lib -> usr/lib
/lib64 -> usr/lib64
/var/run -> /run
/var/lock -> /run/lock

A few more commands locate a program and what it depends on:

Terminal window
# Check that /bin really is a link to /usr/bin
ls -ld /bin /sbin
# Find where a command lives
which systemctl
type -a ls
# See the libraries a program uses
ldd /usr/bin/ls

/opt/ and /usr/local/: software outside packages

These two directories hold software installed outside the package manager, but with different conventions: /opt/ receives a complete application in its own folder, /usr/local/ receives loose binaries that slot into the usual tree.

DirectoryUseExample
/opt/<vendor>/Complete, self-contained third-party application/opt/google/chrome/, /opt/jetbrains/
/usr/local/bin/Binary compiled or downloaded by handIn-house script, compiled Go/Rust tool

Related guide: Manage packages.

/run/, /proc/, /sys/: volatile runtime data

These three directories are not on disk, and their contents disappear when the machine shuts down. /proc/ and /sys/ are built on the fly by the kernel. /run/ is a tmpfs (a filesystem held in RAM) that systemd and the services fill at every boot. None of the three belongs in a backup. In /run/, a service drops its PID file, which holds the number of its process, and its socket, the contact point through which other programs talk to it.

DirectoryBacked byContents
/run/tmpfsPID files, sockets, locks, runtime state of services
/proc/procfsVirtual view of processes and the kernel
/sys/sysfsVirtual view of the hardware and drivers
Terminal window
# See a service's PID through /run
cat /run/sshd.pid 2>/dev/null || echo "No PID file (service stopped or managed by systemd)"
# Read CPU information through /proc
cat /proc/cpuinfo | head -20
# See the total memory
cat /proc/meminfo | grep MemTotal
# Read a kernel parameter through /sys
cat /sys/block/sda/queue/scheduler 2>/dev/null

Related guide: Manage processes.

/home/, /root/, /srv/: user and service data

These three directories hold data, not system files, and they are the ones you back up first. The trap is in the name: /root/ is the home directory of the root account, not the root / of the tree.

DirectoryOwnerContents
/home/<user>/The userPersonal files, local config (~/.bashrc, ~/.ssh/)
/root/rootRoot's home directory (not to be confused with /)
/srv/ServicesData served by the machine (websites, repositories, shares)
Terminal window
# See how much space each user takes
du -sh /home/*/
# Check the permissions of root's home directory
ls -ld /root/

This separation of roles often turns into a partitioning decision. On a multi-user server, mounting /home/ on a separate partition lets you reinstall the system without touching account data: the reinstall overwrites /, and /home is simply mounted again afterwards.

Related guide: Users and groups.

/dev/, /mnt/, /media/: devices and mounting

/dev/ exposes the devices as special files. /mnt/ and /media/ are mount points: the directories where the contents of a disk or a USB stick appear once it is "mounted". /mnt/ is for the administrator; /media/ receives removable media mounted automatically, on some distributions only.

DirectoryContents
/dev/Special files that represent devices (disks, terminals, null, random)
/mnt/Temporary mount point for the administrator
/media/Automatic mount point for removable media (USB, CD) on a Debian 13 desktop

On Ubuntu 26.04, RHEL, AlmaLinux and Fedora, the automatic mounting of a workstation happens in /run/media/<user>/, a directory emptied at every reboot. Debian 13 mounts under /media/<user>/. On a server nothing is mounted by itself: you mount the media yourself, usually under /mnt/.

The device files you will meet most often in /dev/ are these:

DeviceRepresents
/dev/sda, /dev/sdbSATA/SAS disks
/dev/nvme0n1NVMe disk
/dev/vdavirtio disk (KVM virtual machine)
/dev/nullThrows away everything written to it (redirect there whatever you want to ignore)
/dev/zeroEndless source of zeros
/dev/random, /dev/urandomRandom number generators
/dev/tty*, /dev/pts/*Terminals
Terminal window
# List disks and partitions
lsblk
# See the available block devices
ls -l /dev/sd* /dev/nvme* /dev/vd* 2>/dev/null

Related guides: Storage overview, Identify disks, Persistent mounts.

/boot/: boot files

/boot/ contains the Linux kernel, the initramfs (the initial filesystem image, loaded before the root filesystem) and the boot loader configuration. It is a critical directory: a clumsy change can stop the system from booting.

FileRole
vmlinuz-*Compressed Linux kernel
initrd.img-* / initramfs-*Initial filesystem image (drivers, LVM, encryption)
grub/GRUB2 boot loader configuration
config-*Kernel build options
System.map-*Kernel symbol table (debugging)
Terminal window
# See the installed kernels
ls -lh /boot/vmlinuz-*
# See how much space /boot uses
df -h /boot

Related guide: Reboot and shut down.

/tmp/ and /var/tmp/: temporary files

Both directories hold temporary files, but they do not have the same lifetime, and the cleaning rules differ from one distribution to another. The type of /tmp (disk or tmpfs) was read on Ubuntu 24.04, Ubuntu 26.04, Debian 13 and AlmaLinux 10. The effect of a reboot on /tmp was tested on Ubuntu 26.04, Debian 13 and AlmaLinux 10, and is deduced from the D rule on Ubuntu 24.04. The durations come from the rules shipped with the packages; the purge itself was not tested.

DirectoryLifetimeCleaning
/tmp/Until the next reboot on Ubuntu 24.04, Ubuntu 26.04 and Debian 13; kept on AlmaLinux 10Ubuntu 24.04: /tmp on disk, emptied at boot by systemd-tmpfiles (rule D). Debian 13 and Ubuntu 26.04: tmpfs in RAM, with the q … 10d rule shipped too. AlmaLinux 10: /tmp on disk and q … 10d rule (files older than 10 days purged), with no emptying at boot
/var/tmp/Kept across rebootsRule q /var/tmp 1777 root root 30d active on Debian 13, Ubuntu 26.04 and AlmaLinux 10, shipped commented out on Ubuntu 24.04
Terminal window
# Which filesystem is /tmp really on?
df -Th /tmp
# See the largest temporary files
du -sh /tmp/* 2>/dev/null | sort -rh | head -10

A common explanation is not true everywhere: "/tmp is a RAM disk, so it empties on reboot". It makes you mispredict how an unknown machine behaves. On an Ubuntu 24.04 machine, df -Th /tmp answers:

Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 14G 2.1G 12G 16% /

That is the root partition in ext4, and /tmp is not even a separate mount point. Fedora, recent Arch and Debian 13 do mount a tmpfs, and so does Ubuntu 26.04, as the Ubuntu Server 26.04 LTS guide shows: hence the confusion.

A script must therefore never count on a reboot to do its cleaning for it: depending on the distribution, /tmp is emptied at boot, or only after a few days.

One last point about this directory, for scripts: create your temporary files with mktemp rather than by hand. The command draws a unique name, which avoids the collisions between two simultaneous runs and the symlink attack, where a third party places a link at the spot your script is about to write.

How do the directories differ between distributions?

The FHS is a standard, but each family of distributions has its own quirks. The log file names and the network configuration directory are two differences you will hit early.

AspectDebian / UbuntuRHEL / Rocky / AlmaLinuxAlpine
System logjournalctl (/var/log/syslog with rsyslog)/var/log/messages (rsyslog)/var/log/messages
Authentication logsjournalctl (/var/log/auth.log with rsyslog)/var/log/secure (rsyslog)/var/log/messages
Package logs/var/log/dpkg.log/var/log/dnf.lognone
Network configUbuntu: /etc/netplan/; Debian: depends on the tool that manages the network/etc/NetworkManager//etc/network/
Package config/etc/apt//etc/yum.repos.d//etc/apk/
Init (PID 1)systemdsystemdOpenRC
usr-mergeYes (Debian 12+)Yes (RHEL 9+)No (separate)

Mini-lab: explore the FHS on a real system

These commands change nothing on the machine. They help you check your understanding by comparing what you read with what the system actually shows.

  1. Spot the functional areas

    Terminal window
    # See the top-level directories
    ls -ld /etc /var /usr /run /proc /sys /boot /tmp /home /dev /srv /opt
  2. Identify the configuration files of a service

    Terminal window
    # Example with SSH
    ls -la /etc/ssh/
    cat /etc/ssh/sshd_config | head -30
  3. Find where a service stores its data

    Terminal window
    # Persistent data
    ls /var/lib/ | head -20
    # Logs
    ls /var/log/ | head -20
  4. Check the virtual filesystems

    Terminal window
    # /proc and /sys are not on disk
    df -Th /proc /sys /run /tmp
  5. Confirm usr-merge

    Terminal window
    # On a modern distribution, /bin is a link
    ls -ld /bin /sbin /lib

Troubleshooting

These 6 symptoms come from a misreading of the tree, and the error message does not always say which directory is at fault. Read the left column as what you see on screen, the middle one as the hypothesis to check first, and the last one as the action that fixes the problem.

SymptomLikely causeFix
No space left on device on /varLogs or caches too largedu -sh /var/log/* | sort -rh, then journalctl --vacuum-size=500M or apt clean
systemd unit edited but not taken into account, or change gone after an updatePackage file edited in /usr/lib/systemd/: an update wipes it, and a copy placed in /etc/systemd/system/ takes precedence over it. Another possible cause: systemctl daemon-reload forgottenCreate the override in /etc/systemd/system/ and run systemctl daemon-reload
Command not found after a manual installBinary placed outside the PATHMove it to /usr/local/bin/ or add its path to the PATH
/boot full, kernel update impossibleOld kernels not purgedapt autoremove (Debian) or dnf remove --oldinstallonly (RHEL)
Temporary file gone after rebootPlaced in /tmp/, emptied at boot by systemd-tmpfiles (Ubuntu 24.04) or lost with the tmpfs (Debian 13, Ubuntu 26.04)Use /var/tmp/ for files that must survive a reboot
Permission denied on a file in /run/PID file or socket owned by another serviceCheck the owner with ls -la /run/<file>, do not change permissions by hand

Put it into practice

The tree sticks by walking through it. The lab prepares a separate working folder on your computer, with an fhs.txt file to fill in. The commands act on your own machine, which must be a Linux (Linux computer, Ubuntu in WSL2 on Windows 11, or Linux VM): you locate four real items there, the ls command, the file that lists the local user accounts, the directory of the system logs and the directory that holds the home folders, then write their absolute path into the file. Validation checks that each path really exists where you say it does.

Key points

  • The FHS organises Linux into functional areas: /etc/ for configuration, /var/ for variable data, /usr/ for binaries, /run/ for volatile runtime data.
  • Three administration reflexes: config → /etc/, problem → /var/log/ or journalctl, runtime → /run/.
  • Never edit a systemd unit shipped by a package (/usr/lib/systemd/): copy it into /etc/systemd/system/ to override it.
  • /proc/, /sys/ and /run/ are not on disk: keep them out of your backups.
  • /tmp/ is emptied at boot on Ubuntu and Debian, not on AlmaLinux 10, which only purges what is older than ten days. Use /var/tmp/ for temporary files that must persist.
  • System logs vary with the distribution: on Debian, rsyslog has no longer been installed by default since Debian 12, so journalctl alone until the package is installed (then syslog and auth.log appear); messages and secure, written by rsyslog, on RHEL and AlmaLinux.

Knowledge check

Check that the essentials of this guide stuck. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer

FAQ: frequently asked questions

These are the questions that come up when you discover the tree, and they cover costly confusions: the difference between /root and the root /, where to put software installed by hand, and what is safe to delete to free up space.