Skip to main content

Linux Filesystem

The one-sentence version

Linux presents everything as one tree rooted at /, where the name of a file and the file itself are separate things — directory entries hold names, inodes hold the file.

The directory layout

The Filesystem Hierarchy Standard assigns meaning to each top-level directory so software and administrators can predict paths across distributions.

PathHolds
/etcSystem-wide configuration
/varVariable data — logs, caches, spool
/tmpTemporary files, typically cleared on reboot
/homeUser home directories
/usrUser programs, libraries, read-only data
/procVirtual filesystem exposing kernel and process state
/devDevice nodes

/bin versus /usr/bin is a historical artifact worth knowing. /bin held the binaries needed to boot into single-user mode, back when /usr might live on a separate or network-mounted partition unavailable that early. That constraint is gone, so modern distributions symlink /bin to /usr/bin.

Names, inodes, and data

A file has three distinct parts, and separating them explains a surprising amount of behaviour.

The inode stores everything about a file except its name and its contents. The name lives in the directory entry that points at the inode.

ls -i file.txt # show the inode number
stat file.txt # show the full inode contents
df -i # inode usage per filesystem

This distinction falls straight out of the model above.

Hard linkSymbolic link
Own inodeNo — shares the target'sYes
ContentsN/AA path string
Survives target renameYesNo, becomes dangling
Can cross filesystemsNoYes
Can point at a directoryNo (generally)Yes

A file's data is freed when its inode link count reaches zero. That is why deleting one of two hard links does not lose the data, and why deleting a file that a running process still holds open frees nothing until the process exits.

When the disk is full but isn't

A classic incident. Writes fail with No space left on device, but df -h shows plenty of free space.

df -h # bytes: 20% used
df -i # inodes: 100% used <- the actual problem

Every file consumes an inode regardless of size, and the count is fixed at filesystem creation. Millions of tiny files — session data, unrotated logs, cache entries — exhaust inodes long before they exhaust bytes.

Questions

Loading questions…

Learn more