Linux › Section B · Basic commands and the directory hierarchy › Topic B.13
Linux directory hierarchy essentials
Every Linux system lays out its files in much the same way: programs here, configuration there, logs somewhere else. Once you know the map, you can find the settings, logs and programs of a machine you have never seen before.
One tree and a standard map
Linux has a single directory tree that starts at the root directory, /. There are no drive letters: extra disks, USB sticks and network shares are attached at directories inside the tree, as Mounting filesystems and /etc/fstab explains. The layout itself follows the Filesystem Hierarchy Standard (FHS), published by the Linux Foundation and, since late 2025, maintained by freedesktop.org; its current version, 3.0, dates from 2015. Distributions differ in details, but the main directories and their purposes are the same everywhere, which is why instructions written for one distribution usually work on another. Running ls / shows the top level.
Where programs live
/bin holds essential commands such as ls and cp, and /sbin holds system administration programs such as fdisk, many of which work only for root. /usr/bin and /usr/sbin hold the great majority of installed programs. The split once let a small root filesystem boot before a separate /usr was mounted, but most distributions have now merged them: /bin, /sbin and /lib are symbolic links to their counterparts under /usr. Fedora made this change in release 17 in 2012, and Debian 12 (2023) supports only the merged layout. On such systems ls -l /bin shows bin -> usr/bin, and /bin/ls and /usr/bin/ls are the same file.
Configuration and home directories
/etc, usually pronounced et-see, holds the system's configuration: user accounts in /etc/passwd, mounted filesystems in /etc/fstab, host names in /etc/hosts, and settings for most services in files or subdirectories named after them, such as /etc/ssh. Nearly everything there is plain text. /home holds one personal directory per ordinary user, such as /home/ana, where that user's files and personal settings live. The administrator's home is /root, not /home/root, so that it is available even when /home is on a separate disk that has not been mounted. The topic The structure of /etc looks at /etc in detail.
Libraries and kernel files
/lib, or /usr/lib on merged systems, holds shared libraries: code that many programs load when they run, such as the C library. 64-bit systems may also have /lib64 or per-architecture subdirectories of /usr/lib on Debian-family systems. Loadable kernel modules, the pieces of the kernel that can be added while it runs, live in /lib/modules, in a subdirectory named after each kernel version; uname -r prints the running version. The kernel image itself is a file in /boot, usually named vmlinuz followed by the version, and the boot loader loads it into memory at start-up.
Data that changes: /var, /tmp and /run
/var holds variable data that programs write while the system runs: logs in /var/log, caches in /var/cache, queued work such as print jobs in /var/spool, and program state such as package databases in /var/lib. /tmp is a scratch area that every user can write to, protected by the sticky bit so users cannot delete each other's files. On many current distributions /tmp is held in memory and emptied at every boot, so never keep anything important there. /var/tmp is also for temporary files, but it is preserved across reboots. /run holds runtime data such as process ID files and sockets, rebuilt at every boot; /var/run is a symbolic link to it.
Virtual directories
Some directories are not stored on disk at all; the kernel generates their contents on demand. /proc presents information about running processes, with one numbered directory per PID, plus system details such as /proc/cpuinfo and /proc/meminfo. /sys presents the kernel's view of devices, drivers and settings, as The sysfs device path and dd explains. /dev holds device files, the entries through which programs reach hardware such as disks and terminals, covered in Device files. Because these files are generated live, reading the same file twice can give different results, and most of them report a size of zero in ls -l.
Other top-level directories
/boot holds the kernel, the initial RAM filesystem and the boot loader's files, used only during the first stage of start-up. /media is where removable media such as USB sticks are mounted; desktop systems often mount them per user, under /media/ana on Ubuntu or /run/media/ana on Fedora. /mnt is a conventional place for an administrator's temporary mounts. /opt holds add-on software packages that keep all their files together, such as some commercial applications. /srv holds data served by the system, such as a web server's files, although many distributions use /var/www or /var/lib instead.
Inside /usr
/usr, despite the name, holds no user files: it is where most of the operating system's programs and data live. Besides bin, sbin and lib, it contains include, the header files used by the C compiler; share, data that does not depend on the processor type, including man for manual pages and doc for package documentation; and local. /usr/local has its own bin, lib and share and is reserved for software the administrator installs by hand. The package manager never touches it, so a program compiled from source and installed in /usr/local/bin cannot be overwritten by a system update. Repeating names such as bin and lib at each level is deliberate, so each level is laid out the same way.
Worked example: finding things on a new server
You are asked to fix a misbehaving web server on a machine you have never used. 1. Configuration belongs in /etc, so look for a directory named after the service: ls /etc | grep -i nginx finds /etc/nginx. 2. Logs belong under /var/log, so ls /var/log/nginx shows access and error logs. 3. To learn which program actually runs, type nginx prints its path, such as /usr/sbin/nginx. 4. Website files are often in /var/www or /srv; the configuration file names the real location. 5. Runtime files such as the PID file are in /run. 6. You found everything without documentation, purely from the FHS conventions.
Worked example: choosing an install location
You have compiled a small tool called logsum from source and want every user to be able to run it. 1. /usr/bin belongs to the package manager, which may overwrite or delete files there during updates, so avoid it. 2. /usr/local/bin is meant for locally installed programs and is normally on every user's PATH already, so sudo install logsum /usr/local/bin installs it there; install copies the file and gives it mode 755 by default. 3. A large vendor package with its own libraries and data would go under /opt instead, such as /opt/vendorapp. 4. Check with type logsum, which should print /usr/local/bin/logsum. 5. Keep personal-only tools in ~/bin or ~/.local/bin.
Common mistakes to avoid
First, storing important files in /tmp, which may be wiped at the next boot. Second, installing hand-built software into /usr/bin, where package updates can overwrite it, instead of /usr/local or /opt. Third, assuming /usr means user and keeping personal data there. Fourth, confusing /root, the administrator's home, with /, the root directory. Fifth, treating files in /proc and /sys as ordinary files that can be copied or backed up meaningfully. Sixth, letting /var fill up with logs, which can stop services and logins working.
Key takeaways
Linux has one tree rooted at /, laid out by the Filesystem Hierarchy Standard. Programs live in /usr/bin and /usr/sbin, with /bin, /sbin and /lib now usually links into /usr. /etc holds configuration, /home users' files and /root the administrator's. /var holds logs, caches, spools and state; /tmp is temporary and may be cleared at boot, /var/tmp survives, and /run holds runtime data. /proc, /sys and /dev are generated by the kernel. /boot holds the kernel, /lib/modules its modules, and /usr/local and /opt locally installed software.
Flashcards
Flashcard
The root directory, top of the single tree
Test your understanding
Question 1 of 5
Where would you expect to find the configuration for an SSH server?
Question 2 of 5
A script writes its only copy of a day's results to /tmp/results.csv. Why is this risky?
Question 3 of 5
On a current Fedora or Debian system, ls -l / shows bin -> usr/bin. What does this mean?
Question 4 of 5
You compiled a tool from source for all users. Which location follows the FHS and is safe from package updates?
Question 5 of 5
Which directory holds kernel-generated information about running processes, one numbered directory per PID?
