Linux Administration
The Linux Filesystem: Hierarchy, Paths, Links, Mounts and Disks
Beginner10 min readReviewed by Mariem Ouled on Updated
After reading this you will know what each top-level directory is for, how to read an ls -l line, why hard links and symbolic links behave differently, how partitions are attached to the tree with mount and /etc/fstab, and how to find where the disk space went. Examples target current Debian/Ubuntu and RHEL-family systems.
What you will learn
- Describe the purpose of the main FHS directories such as /etc, /var, /usr, /opt, /proc and /run
- Read an ls -l line and identify the file type, permissions, link count, owner and size
- Explain the difference between a hard link and a symbolic link and choose the right one
- Inspect block devices and mounts with lsblk, findmnt and df, and add a persistent entry to /etc/fstab
- Locate files with find and measure directory sizes with du
Linux has no drive letters. There is one tree, rooted at /, and every disk, USB stick, network share and even the kernel's own bookkeeping is grafted onto it somewhere. Once you know the conventions for where things go, an unfamiliar server stops being a maze: configuration is in /etc, variable data in /var, the kernel's live view of the machine in /proc, and so on. This guide walks the tree, explains the objects that live in it (files, directories, links, devices) and shows how storage is attached to it and inspected.
One tree, many filesystems
The word filesystem is used for two different things, and keeping them apart avoids a lot of confusion.
The directory tree is the logical namespace: /home/alice/notes.txt is a path in the tree. A filesystem in the storage sense is a data structure on a block device — ext4, XFS, Btrfs, FAT — that stores files and directories. The tree is assembled at boot by mounting filesystems onto directories: the root filesystem is mounted on /, and further filesystems can be mounted on /boot, /home, /var/lib/postgresql or anywhere else. To a program walking the tree the seams are invisible.
Debian and Ubuntu install with ext4 by default; RHEL-family distributions (Rocky Linux, AlmaLinux, RHEL) default to XFS. Both are mature journaling filesystems; XFS cannot be shrunk after creation, which is the main operational difference you are likely to hit.
The standard directories
The Filesystem Hierarchy Standard (FHS) defines the layout below. Distributions follow it closely, with a few modern twists noted along the way.
| Directory | What lives there |
|---|---|
/bin, /sbin, /lib | On current distributions these are symbolic links into /usr (the "usr merge"). sbin historically held administrator-only binaries. |
/usr | The bulk of installed software: /usr/bin for commands, /usr/lib and /usr/lib64 for shared libraries, /usr/share for architecture-independent data such as man pages and locale files. Read-only in normal operation. |
/usr/local | Software you build or install by hand, laid out like /usr. Package managers never write here, so nothing you put in /usr/local/bin will be overwritten by an update. |
/opt | Self-contained third-party applications, one directory each (/opt/jdk-21, /opt/myapp). |
/etc | Host-specific configuration, as plain text. No binaries. |
/var | Data that changes while the system runs: logs (/var/log), package caches (/var/cache/apt), application state (/var/lib/mysql), mail spools, and /var/tmp for temporary files that must survive a reboot. |
/home | Users' home directories. /root is the home of the superuser, kept separate so it is available even if /home fails to mount. |
/tmp | Scratch space that may be wiped at boot (often a RAM-backed tmpfs). |
/run | Runtime state since the last boot: PID files, sockets, lock files. A tmpfs, empty after every reboot. |
/boot | The kernel image, initial RAM disk and bootloader files. Often a separate small partition. |
/dev | Device files, populated dynamically by the kernel and udev. |
/proc, /sys | Virtual filesystems exposing kernel and hardware state; they occupy no disk space. |
/srv | Data served by the machine (web content, FTP trees) when the administrator prefers to keep it out of /var. |
/mnt, /media | Temporary mount points for the administrator and for removable media respectively. |
/lost+found | Where fsck puts orphaned data it recovers on an ext filesystem. One exists per ext filesystem. |
A few of these deserve a closer look.
/etc: configuration as text
Almost everything about how a host behaves is a readable file under /etc: /etc/hostname, /etc/hosts, /etc/fstab, /etc/passwd, /etc/ssh/sshd_config, /etc/systemd/system/ for your service units, /etc/nginx/ or /etc/httpd/ for web servers. Because it is plain text, /etc can be diffed, version-controlled and audited with grep. When something behaves unexpectedly, grep -r through /etc is frequently faster than reading documentation.
Many packages support a *.d drop-in directory next to their main file — /etc/sudoers.d/, /etc/apt/sources.list.d/, /etc/systemd/system/app.service.d/. Put your changes in a new file there rather than editing the package's file, and upgrades will not clobber them.
/proc and /sys: the kernel as files
/proc is a window into the running kernel. /proc/cpuinfo and /proc/meminfo describe the hardware; /proc/loadavg is what uptime reads; each process has a directory /proc/<pid>/ containing its command line, environment, open file descriptors (fd/), memory maps and current working directory. Tools such as ps, top and lsof do nothing more exotic than read these files.
cat /proc/loadavg # 0.42 0.31 0.28 1/412 18342
ls -l /proc/$$/fd # file descriptors of the current shell
cat /proc/$(pgrep -o nginx)/cmdline | tr '\0' ' '
/sys exposes the device model: which drivers are bound to which devices, block device parameters, network interface statistics. Writing to some of its files changes kernel behaviour at runtime (for example the I/O scheduler of a disk in /sys/block/sda/queue/scheduler).
/dev: everything is a file
Devices appear as special files so the same open/read/write calls work on a disk, a terminal or a random-number source. Disks show up as /dev/sda, /dev/nvme0n1, /dev/vda and their partitions as /dev/sda1, /dev/nvme0n1p1. A few pseudo-devices are used daily:
/dev/nulldiscards everything written to it and reads as empty — the standard place to send unwanted output./dev/zeroproduces an endless stream of zero bytes, handy for creating blank files./dev/urandomproduces random bytes./dev/ttyis the controlling terminal of the current process.
Reading an ls -l line
ls -l packs a lot into one line. Take this entry from /etc:
-rw-r--r-- 1 root root 1354 Mar 14 09:12 fstab
drwxr-xr-x 2 root root 4096 Aug 30 17:40 cron.d
lrwxrwxrwx 1 root root 21 Jan 6 10:02 localtime -> /usr/share/zoneinfo/UTC
From left to right: the file type (- regular file, d directory, l symbolic link, c character device, b block device, s socket, p named pipe), nine permission bits in three groups for owner, group and everyone else, the hard link count, the owner, the group, the size in bytes, the modification time, and the name. Permissions get their own guide in Users, groups and permissions.
Two details trip people up. Files whose names start with a dot are hidden from a plain ls; use ls -a (or -A to skip . and ..). And the size of a directory shown by ls is the size of its entry list, not of its contents; for that you need du.
Inodes, hard links and symbolic links
Every file on a filesystem is described by an inode: a record holding the owner, permissions, timestamps, size and the list of data blocks — everything except the name. A directory is simply a table that maps names to inode numbers. ls -i shows the numbers and stat shows the whole record:
$ stat /etc/fstab
File: /etc/fstab
Size: 1354 Blocks: 8 IO Block: 4096 regular file
Device: 259,2 Inode: 1572867 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Because the name is not part of the inode, one inode can have several names. A hard link is a second directory entry for the same inode; the Links count above tells you how many exist. Deleting a name only decrements the count, and the data is freed when it reaches zero and no process holds the file open. Hard links cannot cross filesystems (inode numbers are per filesystem) and cannot point at directories.
A symbolic link (symlink) is a different animal: a small file whose content is a path. The kernel follows that path when you open the link. Symlinks can point anywhere, including to directories, to other filesystems, or to targets that do not exist yet — a dangling link.
ln /var/lib/app/data.db /backup/data.db # hard link: same inode
ln -s /opt/app-2.4.1 /opt/app # symlink: "current version" pointer
readlink -f /opt/app/bin/start # resolve every link in the path
The /opt/app -> /opt/app-2.4.1 pattern is a common deployment idiom: unpack the new release next to the old one, then swap the link atomically with ln -sfn /opt/app-2.5.0 /opt/app. Rolling back is another ln.
A relative symlink (ln -s ../shared/config.yml config.yml) is resolved relative to the directory containing the link, which keeps it valid if the whole tree is moved or copied; an absolute one breaks in that case. Prefer relative targets inside a project tree and absolute targets for system-wide pointers.
Paths and navigation
An absolute path begins with /; a relative path is resolved against the current working directory, which pwd prints and cd changes. Two special entries exist in every directory: . (the directory itself) and .. (its parent). The shell expands ~ to your home directory and ~bob to Bob's.
cd /var/log # absolute
cd ../lib # relative: /var/lib
cd - # back to the previous directory
cd # home
The everyday file commands are ls, cp, mv, rm, mkdir and rmdir. Three flags matter more than the rest: mkdir -p creates intermediate directories and does not complain if the path exists; cp -a copies recursively while preserving permissions, ownership, timestamps and symlinks (what you want for backups, unlike plain cp -r); and rm -rf removes without asking — type the path, look at it, then press Enter.
Disks, partitions and mounts
lsblk draws the storage picture: devices, their partitions, sizes, filesystem types and where each is mounted.
$ lsblk -f
NAME FSTYPE FSVER LABEL UUID MOUNTPOINTS
nvme0n1
├─nvme0n1p1 vfat FAT32 6E1A-3B7C /boot/efi
├─nvme0n1p2 ext4 1.0 3f2c8a1e-4b5d-4f6a-9c1d-2e3f4a5b6c7d /
└─nvme0n1p3 swap 1 9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d [SWAP]
findmnt lists mounts as a tree with their options; mount with no arguments prints the same information in the older flat form. To attach a filesystem by hand:
sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data
sudo umount /mnt/data # fails with "target is busy" if any process is using it
A manual mount disappears at reboot. Persistent mounts are declared in /etc/fstab, one line per filesystem: device, mount point, type, options, and two numbers for dump and fsck ordering.
# <device> <mount> <type> <options> <dump> <pass>
UUID=3f2c8a1e-4b5d-4f6a-9c1d-2e3f4a5b6c7d / ext4 errors=remount-ro 0 1
UUID=6E1A-3B7C /boot/efi vfat umask=0077 0 1
UUID=b1c2d3e4-f5a6-4b7c-8d9e-0f1a2b3c4d5e /srv/data xfs defaults,nofail 0 2
Identify devices by UUID (from blkid or lsblk -f), never by /dev/sdX: device names depend on probe order and can change when a disk is added. The nofail option tells the boot process to carry on if that device is missing, which is the difference between a server that boots without its data disk and one that drops into an emergency shell. After editing fstab, sudo mount -a mounts everything not yet mounted and validates your syntax before you find out at the next reboot; on systemd hosts run sudo systemctl daemon-reload first so the generated mount units are refreshed.
Where did the space go?
df reports free space per mounted filesystem; du measures what a directory tree occupies. Used together they answer most "disk full" alerts.
df -h # human-readable sizes, one line per filesystem
df -i # inode usage — a filesystem can be "full" with free bytes
sudo du -sh /var/* | sort -h # which top-level directory under /var is biggest
sudo du -xh --max-depth=2 /var/log | sort -h | tail
du -x stays on one filesystem, which matters when /proc or a network mount would otherwise be counted. Running out of inodes is a classic failure of mail queues and session directories that hold millions of tiny files.
When df and du disagree, look for deleted-but-open files:
sudo lsof -nP +L1 # files with a link count of 0 that are still open
A log file that was rm'd while the service kept writing is the usual culprit. Truncating it through the file descriptor releases the space without a restart: : > /proc/<pid>/fd/<n>.
Finding files
find walks a tree and applies tests and actions to every entry. Its expression language rewards learning a handful of primitives:
find /var/log -name '*.log' -size +100M # large logs
find /etc -type f -mtime -1 # files changed in the last 24 h
find /srv/app -type d -name node_modules -prune -o -name '*.js' -print
find /tmp -type f -atime +7 -delete # clean old scratch files
find . -name '*.orig' -exec rm -v {} + # run rm once with many paths
find /home -type f -perm -o+w # world-writable files: a red flag
-mtime -1 means "modified less than one day ago", +7 "more than seven days"; the same sign convention applies to -size. Quote patterns so the shell does not expand them before find sees them. -exec ... {} + batches paths into as few command invocations as possible, whereas \; runs the command once per file.
For file names only, locate (package plocate or mlocate) answers from a nightly index in milliseconds; run updatedb after installing it. which and type tell you which executable a command name resolves to.
Archiving and copying trees
tar bundles a directory tree into one file, usually compressed:
tar -czf site-2026-09-07.tar.gz -C /var/www example.com # create, gzip
tar -tzf site-2026-09-07.tar.gz | head # list contents
tar -xzf site-2026-09-07.tar.gz -C /tmp/restore # extract elsewhere
tar --zstd -cf app.tar.zst --exclude='*.log' /opt/app # zstd: faster, comparable ratio
-C dir changes directory before archiving so the archive stores example.com/... rather than var/www/example.com/.... Always list an archive from an unknown source before extracting: one created from / with absolute paths can overwrite system files.
For copying trees between directories or hosts, rsync -a beats cp and scp: it preserves metadata, skips files that have not changed, and resumes after interruption.
rsync -a --delete /srv/data/ backup:/srv/data/ # mirror; trailing slash = "contents of"
Common mistakes
Mounting by device name. /dev/sdb1 in fstab works until a new disk shifts the letters. Use UUID= or LABEL=.
Confusing cp -r with cp -a. Plain recursive copy follows symlinks, resets ownership to the caller and updates timestamps. Backups and migrations want -a.
Putting data in /tmp. It may be RAM-backed and is commonly cleaned at boot or by a timer. Use /var/tmp if the data must survive a reboot, or the proper /var/lib/<app> location if it is really state.
Editing packaged files in /etc directly. The next upgrade may prompt you to merge changes or silently replace them. Use the package's .d directory or an override mechanism where one exists.
Deleting a file to free space while it is open. The space is not returned until the writer closes it. Truncate instead (: > file), or rotate the log properly.
Extracting untrusted tarballs as root. Inspect with tar -tf first, extract into an empty directory, and never extract archives containing absolute paths or .. components.
Key takeaways
- There is one tree; disks, virtual filesystems and network shares are mounted onto directories in it.
- The FHS tells you where things belong:
/etcfor configuration,/varfor changing data,/usrfor installed software,/optand/usr/localfor software outside the package manager,/runand/tmpfor transient files. - An inode holds everything about a file except its name; hard links are extra names for one inode, symlinks are files containing a path.
lsblk,findmntanddfshow storage;/etc/fstabmakes mounts persistent and should reference devices by UUID withnofailon non-essential disks.du -xh --max-depth,df -iandlsof +L1between them explain almost every "disk full" incident.findwith-name,-type,-mtime,-sizeand-exec ... +replaces a great deal of ad-hoc scripting.
Sources and further reading
Frequently asked questions
- What is the difference between /usr/local and /opt?
- Both hold software that did not come from the distribution's package manager. /usr/local mirrors the /usr layout (bin, lib, share) and is meant for things you build or install yourself that should blend into the system PATH. /opt holds self-contained third-party packages that keep all their files in one directory, such as /opt/myapp, which makes them easy to remove as a unit.
- Why can't I create a hard link to a directory or across drives?
- A hard link is just another directory entry pointing at the same inode, and inode numbers are only meaningful within one filesystem, so a link cannot cross a mount boundary. Hard links to directories are refused because they would allow cycles in the tree, which would break every tool that walks it. Use a symbolic link in both cases.
- Where should my application write its data and logs?
- Persistent state belongs under /var/lib/<app>, logs under /var/log/<app> (or the journal), caches that can be rebuilt under /var/cache/<app>, and runtime files such as PID files or sockets under /run/<app>. Configuration goes in /etc/<app>. Keeping to these conventions means backups, log rotation and monitoring tools find your files where they expect them.
- Why does df say the disk is full when du cannot find the files?
- Usually a process still holds a deleted file open. The directory entry is gone, so du does not count it, but the blocks are not released until the last file descriptor closes. Run lsof +L1 (or lsof -nP | grep deleted) to find the process, then restart it or truncate the file through /proc/<pid>/fd.