The Library Card Analogy
When you create a file named report.txt, you might think the filename and the data are stored together as one unit. They are not.
Linux separates the filename from the actual file metadata and data. This separation is fundamental to understanding how the filesystem actually works, and it explains behaviors that otherwise seem mysterious — like why renaming a 10GB file is instantaneous.
The Three Layers:
-
The Data Blocks: The actual contents of your file (the text inside
report.txt) sit in data blocks scattered across the physical disk. A large file might be spread across hundreds of non-contiguous blocks. -
The Inode (Index Node): Linux uses a structure called an inode to store everything about the file except its name. Each inode contains:
- File type (regular file, directory, symlink, device, socket, etc.)
- Owner (user ID) and group (group ID)
- Permissions (read/write/execute for owner/group/others)
- Timestamps:
atime(last accessed),mtime(last modified),ctime(inode last changed) - File size in bytes
- Pointers to the data blocks where the actual content lives
- Link count (how many filenames point to this inode)
Every inode has a unique number within its filesystem. Inode numbers are not globally unique — two different filesystems can each have an inode number 12345.
- The Directory Entry: A directory is just a simple table mapping human-readable filenames to inode numbers. That's it. The directory doesn't know anything about file size, permissions, or content — it just knows "the name
report.txtcorresponds to inode 12345."
The Library Analogy:
- The books on the shelves are the actual data blocks.
- The card catalog entry for each book is the inode. It tells you the author, publication date, number of pages, and which shelf (data block addresses) to find it on.
- The title index that helps you find the card is the directory entry — it maps the title you know to the catalog entry you need.
Why This Matters
This separation has practical consequences you will encounter regularly:
-
Renaming is instant: When you rename a file, Linux only updates the directory entry. The inode and data blocks are untouched. Renaming a 10GB file takes the same time as renaming a 10-byte file.
-
Moving within a filesystem is instant: Moving a file to a different directory on the same filesystem just updates directory entries. No data is copied. This is why
mv /var/data/bigfile.tar /var/backup/bigfile.taris instantaneous. -
Moving across filesystems is slow: Moving to a different filesystem requires copying all data blocks and creating a new inode. That's why
mvacross partitions can take minutes for large files — it's actually a copy followed by a delete. -
Deleting doesn't immediately free space: Deleting a file removes the directory entry and decrements the inode's link count. The data blocks are only freed when the link count reaches zero and no process has the file open. This is the source of the classic "deleted file still consuming disk space" problem.
You can view a file's inode number with ls -li report.txt, which prefixes the normal listing with the inode number — e.g. 12345 -rw-r--r-- 1 jane users 4096 Jan 15 10:30 report.txt. The leading 12345 is the inode; the 1 after the permissions is the link count, meaning exactly one directory entry points to this inode.
Key Point: Inodes are finite. When a filesystem is created, a fixed number of inodes are allocated based on the total size and the bytes-per-inode ratio (typically one inode per 16KB of space by default on ext4). You can have gigabytes of disk space available but be completely unable to create new files if you've exhausted all inodes. This catches engineers off guard because standard disk monitoring only tracks space, not inode usage. Always monitor both with df -h (space) and df -i (inodes).