What is the Linux inode and what information does it store?
Understand the Linux inode: the metadata it stores like permissions, ownership, size, timestamps and block pointers, plus how hard links work.
Expected Interview Answer
An inode is a data structure that stores all the metadata about a file except its name and its actual data, and it uniquely identifies each file within a filesystem by its inode number.
Each inode holds attributes such as file type, permissions, owner and group IDs, size, timestamps, link count, and pointers to the disk blocks that contain the file's contents. Filenames are kept separately in directory entries, which simply map a name to an inode number, which is why multiple hard links can point to the same inode. When the link count of an inode reaches zero and no process has it open, the filesystem frees its data blocks.
- Separates metadata from filename, enabling hard links
- Gives every file a unique identifier per filesystem
- Stores permissions, ownership and timestamps efficiently
- Points directly to data blocks for fast access
- Enables reference counting for safe deletion
AI Mentor Explanation
An inode is like a player's official registration card: it records height, age, batting style, and team, but not the name printed on the jersey. Many scorecards (directory entries) can list a jersey name that points to the same registration ID, and the player only leaves the tournament when every card referencing them is torn up.
Step-by-Step Explanation
Step 1
Recognize what an inode is
It is an on-disk structure holding a file's metadata and pointers to its data blocks.
Step 2
List what it stores
File type, permissions, UID/GID, size, timestamps (atime, mtime, ctime), link count, and block pointers.
Step 3
Know what it does NOT store
The filename lives in the directory entry, not the inode; directories map names to inode numbers.
Step 4
Understand hard links
Multiple names can reference one inode; the link count tracks how many names point to it.
Step 5
Understand deletion
Data blocks are freed only when the link count hits zero and no process still holds the file open.
What Interviewer Expects
- Definition of an inode and its role
- The metadata fields an inode stores
- Awareness that filenames are stored in directory entries, not inodes
- How hard links relate to inodes and link count
- How reference counting governs deletion
Common Mistakes
- Thinking the inode stores the filename
- Confusing an inode with the file's data blocks
- Believing hard links copy the file rather than share an inode
- Not knowing the ctime tracks metadata changes, not creation
- Assuming inode numbers are unique across different filesystems
Best Answer (HR Friendly)
“An inode is Linux's index card for a file. It records everything about the file, like its size, owner, permissions, and where its data sits on disk, but not its name. The name is stored separately, which is how one file can have several names pointing to the same inode.”
Code Example
# Show inode numbers next to filenames
ls -li
# View an inode's metadata: type, permissions, links, timestamps
stat report.txt
# Create a hard link: two names, one inode, link count becomes 2
ln report.txt report_backup.txt
# Check inode usage on the filesystem
df -iFollow-up Questions
- How does a hard link differ from a symbolic link at the inode level?
- What does the link count in an inode represent?
- Can you run out of inodes while disk space remains? Why?
- What are the atime, mtime and ctime timestamps in an inode?
- Why can hard links not span across different filesystems?
MCQ Practice
1. Which piece of information is NOT stored in an inode?
Filenames are stored in directory entries that map a name to an inode number; the inode itself holds metadata and block pointers, not the name.
2. When are a file's data blocks actually freed?
Deletion is reference-counted: blocks are released only once the link count is zero and no open file descriptor still references the inode.
Flash Cards
What is an inode? — A structure storing a file's metadata and block pointers, identifying it uniquely within a filesystem.
Where is the filename stored? — In the directory entry, which maps a name to an inode number, not in the inode itself.
What is the link count? — The number of hard links (directory entries) pointing to an inode; at zero the file's blocks can be freed.
Which timestamps does an inode keep? — atime (access), mtime (content modification), and ctime (metadata change).