One of the most perplexing storage errors in Linux occurs when an application or command fails with the message No space left on device, yet running df -h reveals gigabytes or even terabytes of free disk capacity. On Linux filesystems like ext4, storage capacity is divided into two distinct limits: physical disk block storage (bytes) and index nodes (inodes). Every file, directory, and symbolic link consumes exactly one inode. If your system generates millions of tiny temporary cache files or email spool entries, the filesystem can exhaust all available inodes long before physical disk space fills up.
Checking Inode Usage with the df Command
The standard df utility inspects disk space by default. Passing the -i (inodes) flag transforms the output into an inode audit report.
Open your terminal (Ctrl + Alt + T) and execute:
df -i
To produce human-readable counts formatted with thousands multipliers (K, M, G), add the -h flag:
df -ih
The terminal will display structured storage metrics:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/nvme0n1p2 3.0M 320K 2.7M 11% /
/dev/sda1 15M 15M 0 100% /var/log
Key column explanations:
- Inodes: The total number of unique index nodes allocated to the filesystem upon format.
- IUsed: The quantity of inodes currently assigned to existing files and directories.
- IFree: The remaining count of new files that can be created on that partition.
- IUse%: The percentage of inode capacity consumed. If this reaches 100%, the operating system cannot write new files, regardless of available byte capacity.
Finding Which Directories Consume the Most Inodes
When inode usage reaches critical levels, you must identify which directory contains the runaway collection of tiny files. Run this pipeline command to count files across subdirectories:
sudo find / -xdev -printf '%h\n' | sort | uniq -c | sort -k1 -n | tail -n 15
Command breakdown:
find / -xdev: Searches the root filesystem while staying confined to the single partition.-printf '%h\n': Prints the directory path containing each file.sort | uniq -c: Groups and counts total files per directory.sort -k1 -n | tail -n 15: Displays the top fifteen directories possessing the highest file counts.
Common Causes and Remediation of Inode Exhaustion
Frequent culprits behind inode exhaustion in Ubuntu include:
- PHP and Web Session Directories: Millions of abandoned session files in
/var/lib/php/sessions. Purge them withsudo find /var/lib/php/sessions -type f -delete. - Mail Queue Spools: Unsent cron notification failure reports piling up in
/var/spool/postfix/maildrop. - Package Manager Caches: Accumulated APT headers and orphan packages. Clean them using
sudo apt autoremove --purge && sudo apt clean.