Filesystems · intermediate
Inode and file metadata
In an inode-based Unix filesystem, an inode represents a filesystem object and stores metadata such as its type, permissions, ownership, timestamps, link count, size, and data-location information. Filenames live in directory entries that map names to inode numbers.
Why it matters
This separation explains hard links, why renaming a file usually leaves its data and metadata intact, what stat reports, and why an open but unlinked file can continue consuming storage.
Mental model
How to reason about inode and file metadata
A directory maps a human-readable component to an inode number; the inode then leads to metadata and file content. A path is a route to an object, not a field stored inside that object's inode.
Analogy
A directory entry is a library catalog label and the inode is the catalog record for the item. Several labels can point to the same record, while the record carries the item's properties.
Examples
See the boundary, not just the happy path
Worked example · Inspect inode metadata
stat --format='inode=%i links=%h mode=%A size=%s' report.txtGNU stat obtains metadata for the object reached through report.txt. The inode number is meaningful only within its filesystem, while the link count reports directory entries linked to that inode.
Worked example · Rename without replacing the object
mv draft.txt final.txtWhen source and destination are on the same filesystem, rename normally changes directory entries atomically while retaining the inode and its existing open-file relationships. Cross-filesystem mv requires copy-and-remove behavior instead.
Useful contrast · Filename and inode are separate
ls -li final.txtThe command displays both a directory name and its inode number. Renaming the directory entry can change the displayed name without changing the inode.
Common mistakes
Misconceptions to remove early
Assuming inode numbers are globally unique
An inode number identifies an object only together with its filesystem or device. Different filesystems can use the same inode number.
Assuming every Unix filesystem exposes identical timestamps
Available fields and update semantics vary. For example, birth time is not universally supported, and access-time updates may be disabled or relaxed for performance.
Quick check
Can you predict the result?
1. Where is a regular file's name stored in an inode-based filesystem?
- • In a directory entry that maps the name to an inode number.
- • Inside the file's data blocks as a mandatory header.
- • In the process that most recently opened the file.
2. Why is an inode number insufficient to identify a file across the whole machine?
Keep building