Topic Overview
An inode (index node) is a data structure that stores metadata about files and directories in Unix-like filesystems. Every file has an associated inode that contains crucial information like permissions, timestamps, and disk block locations, but notably NOT the filename itself.
Key Concepts
- Inode Number: Unique identifier for each file within a filesystem
- Metadata Storage: Contains file attributes, not file content or names
- Hard Links: Multiple filenames pointing to same inode
- Inode Table: Filesystem structure storing all inodes
- Inode Exhaustion: Running out of available inodes
Command Syntax
ls -i [options] [files] - Display inode numbers
stat filename - Show detailed inode information
df -i - Check inode usage on filesystems
Common Options
-i - Show inode numbers with ls
-l - Long format (shows links count)
--inode - Alternative to -i flag
Practical Examples
Example 1: View inode numbers
|
|
Shows inode numbers in first column. Note file1.txt and hardlink.txt share same inode (2621441).
Example 2: Detailed inode information
|
|
Displays comprehensive inode metadata including size, permissions, timestamps, and link count.
Example 3: Check inode usage
|
|
Shows total, used, and free inodes per filesystem.
Example 4: Find files by inode
|
|
Locates all files sharing the same inode number.
Use Cases
- File identification: Uniquely identify files regardless of name
- Hard link management: Track multiple names for same file
- Forensics: Recover files or trace file operations
- Backup verification: Ensure file integrity across systems
- Troubleshooting: Diagnose “No space left” errors from inode exhaustion
Related Commands
find -inum - Search by inode number
ln - Create hard/soft links
unlink - Remove directory entry (not file data)
debugfs - Examine filesystem structures directly
tune2fs -l - Show filesystem inode information
Tips & Troubleshooting
Common Issues
- “No space left on device” despite free space: Check
df -ifor inode exhaustion - Cannot delete files: May need root privileges or file has special attributes
- Broken hard links: Use
find -links +1to locate multiply-linked files
Performance Notes
- Inode operations are generally fast (metadata only)
- Excessive hard links can complicate file management
- Some filesystems (FAT32) don’t use traditional inodes
Important Facts
- Filenames are stored in directory entries, NOT inodes
- Deleting a filename decreases link count; file deleted when count reaches 0
- Inode numbers are unique within a filesystem, not across different filesystems
- Moving files within same filesystem preserves inode numbers