Inode
An inode is a filesystem data structure that stores a file's metadata (owner, permissions, size, timestamps, data block locations) but not its name. The name lives in a directory entry that points to the inode number.
Understanding Inodes
What Is an Inode in Linux?
Every file and directory has one inode, with a number unique within its filesystem. The inode records who owns the file, its permissions, size, timestamps, link count, and where its data blocks are. It does not store the filename or the file contents. A directory is just a table mapping names to inode numbers.
Directory /etc/ Inode 1235 (hosts)+------------------------+ +---------------------------+| hostname -> inode 1234 | | Permissions: 644 || hosts -> inode 1235 | ----> | Owner: root Group: root || passwd -> inode 1236 | | Size: 221 bytes |+------------------------+ | Link count: 1 | | Data blocks: [48291] | +---------------------------+How Hard Links and Symbolic Links Differ
A hard link is another directory entry for the same inode, so both names are the same file and the link count goes up. A symbolic link is a separate small file with its own inode that stores a path.
ln /etc/hosts /tmp/hosts-hard # hard link: same inodeln -s /etc/hosts /tmp/hosts-sym # symlink: new inode ls -lai /etc/hosts /tmp/hosts-hard /tmp/hosts-sym# hard link shows the same inode number and link count 2# symlink shows its own inode and an arrow to the target rm /tmp/hosts-hard # link count drops; data stays while any name remainsPractical Inode Commands
ls -i file # inode numberstat file # full inode metadatadf -i # inode usage per filesystemfind / -xdev -inum 1235 2>/dev/null # all names for an inodefind /etc -type f -links +1 # files with several hard links # Find directories holding the most files (inode hogs)for d in /var/*; do echo "$(find "$d" -xdev 2>/dev/null | wc -l) $d"; done | sort -rn | headTroubleshooting Inodes
| Symptom | Command | What to Look For |
|---|---|---|
| Cannot create files, space free | df -i |
IUse% at 100 |
| Two files always identical | ls -lai |
Same inode number |
| Space not freed after delete | lsof +L1 |
Process still has file open |
| Symlink broken | readlink -f link |
Target missing |
TipInode exhaustion hits mail spools, session stores, and build caches that create millions of tiny files. Monitor
df -ialongsidedf -h.
RememberA file's data is freed only when its link count reaches zero and no process still has it open. That is why a deleted file can keep consuming space.
SecurityHard links cannot cross filesystems, and modern kernels add
fs.protected_hardlinks, which stops users from hard-linking files they do not own. Check that this is enabled on shared servers.
Frequently Asked Questions
Why can I run out of space for new files when df shows free space?
Each filesystem has a fixed inode count set at creation. Millions of tiny files can use them all while data blocks remain free. `df -i` shows inode usage, and at 100% no new file can be created.
Why does a hard link share an inode but a symlink does not?
A hard link is just another name pointing at the same inode, so ownership, permissions, and data are identical. A symlink is its own file whose content is a path, so it can cross filesystems and can dangle if the target disappears.
Does the filename live in the inode?
No. The name is stored in the directory entry that maps to the inode number. That separation is what makes hard links and renames cheap.