Unix - Inode Concept in UNIX/Linux
In UNIX-like operating systems, every file is represented internally by a data structure called an inode (index node).
An inode stores metadata about a file, but not the filename and not the file’s data.
1. What is an Inode?
An inode is a data structure on disk that contains all the information about a file except its name and actual content.
Every file and directory has exactly one inode, identified by an inode number.
2. What Information Does an Inode Store?
An inode contains:
-
File type (regular file, directory, symlink, device, pipe, etc.)
-
File size
-
Owner (UID)
-
Group (GID)
-
Permissions (rwx)
-
Timestamps:
-
atime (last access)
-
mtime (last modification)
-
ctime (last metadata change)
-
-
Number of hard links
-
Pointers to data blocks on disk:
-
Direct blocks
-
Indirect blocks
-
Double-indirect blocks
-
Triple-indirect blocks
-
-
Flags (immutable, append-only, etc.)
3. What Inodes Do Not Contain
An inode does NOT store:
-
The filename
-
The file’s directory path
-
File contents
Filenames are stored in directory entries, which map:
filename → inode number
This is why:
-
Multiple filenames (hard links) can point to the same inode.
-
Renaming a file does not change its inode.
4. Inode Number
Each inode has a unique number within a filesystem.
You can view it with:
ls -i
Example:
123456 file.txt
Here, 123456 is the inode number.
5. How Inodes Store File Data
The inode contains pointers to data blocks:
-
Direct blocks: point directly to data (fast for small files)
-
Single indirect: points to a block that contains more pointers
-
Double indirect: pointer to a block of indirect blocks
-
Triple indirect: for very large files
This hierarchical structure allows files to grow to very large sizes.
6. Why Inodes Matter
Disk full but still space left
If the filesystem runs out of inodes, you cannot create new files even if free disk space exists.
Hard links
Hard links point multiple filenames to the same inode.
File deletion behavior
If a file is deleted while a process is using it:
-
The directory entry is removed,
-
But the inode and data remain until no process references it.
Backups and recoveries
Tools like fsck use inode structures to repair filesystems.
7. How to View Inode Information
stat file.txt
This shows:
-
inode number
-
permissions
-
ownership
-
timestamps
-
size
List inode usage on filesystem:
df -i
8. Summary
| Concept | Meaning |
|---|---|
| Inode | Metadata container for a file |
| Does not store | Filename, file content |
| Stored in | Filesystem (ext4, xfs, etc.) |
| Identified by | Inode number |
| Related to | Hard links, file deletion, block pointers |