Linux Filesystem
VFS layer, inodes, hard vs soft links, ext4 and XFS, mount points, and filesystem capacity diagnosis.
Overview
Everything in Linux is a file: devices, processes, network sockets, even hardware. This mental model is the foundation. Before memorizing commands, understand where things live and why the filesystem is organized that way.
The Filesystem Hierarchy Standard (FHS)
Linux follows the FHS so every distribution puts things in predictable places. Everything hangs from one root, /, the top of the tree, and each directory under it has one job.
- /bin and /sbin: essential binaries needed before /usr mounts, for boot recovery. /bin holds essential user binaries such as ls and cp; /sbin holds system binaries such as fsck and ip.
- /usr/bin and /usr/sbin: most user programs. This is where grep, ssh and python3 live.
- /etc: all configuration files, always text, always editable.
- /var: variable data, such as logs in /var/log, databases, mail queues and runtime state.
- /proc and /sys: virtual filesystems that expose kernel state as files. /proc holds kernel and process state, mostly read-only (you read /proc/cpuinfo), with /proc/sys the writable sysctl exception. /sys holds device and driver information, and you write /sys/... to tune the kernel live.
- /dev: device files, such as disks, terminals (tty) and null.
- /home: user home directories. ~ expands to yours.
- /tmp: temporary files, cleared on reboot. It is world-writable with the sticky bit set, so users can delete only their own files.
- /opt: optional third-party packages installed outside the distro package manager.
The 'everything is a file' principle means that disk devices are files (/dev/sda), processes expose state as files (/proc/1/status), and network sockets are file descriptors you read and write like files. This is why Unix tools that work on files compose so well.
Key concepts
- Inode
- Hard link
- Symbolic link
- VFS
- Inode exhaustion
Interview questions
- What is an inode and what happens when inodes are exhausted?
- A file is deleted but disk usage does not decrease. Why and how do you fix it?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio