Inodes and 'No space left on device'
Conceptext4 and similar file systems
An inode is the data structure a Unix-style file system uses to store information about a file, such as its owner, permissions, size and where its data lives. Each file uses one inode, and many file systems have a fixed number, so millions of tiny files can cause 'No space left on device' while df -h still shows free space.
1How to see it
df -i lists total, used and free inodes per file system. ls -i shows a file's inode number, and stat <file> shows its inode details.
2Typical causes
Session or cache directories of web applications, mail queues, unrotated small log files and build caches can create millions of files.
3Finding the directory
GNU du can count inodes: du --inodes -x / | sort -n | tail lists the directories with the most entries.
How to fix inode exhaustion
- Confirm:
df -i(IUse% near 100%). - Find the directory:
sudo du --inodes -x --max-depth=3 / | sort -n | tail -20 - Check what creates the files before deleting anything.
- Remove old files of that application with its own tool, or with find, for example:
find /path -type f -mtime +7 -deleteafter a dry run without -delete.
Cautions
- Always run find without -delete first and read the list.
- The inode count of ext4 is fixed when the file system is created.
Related articles
- df (disk free)How to read df output, why Use% can reach 100% before Avail is zero for normal users, and how to check inodes with df -i.
- Finding large and old files with findHow to use find to list big or old files on Linux, preview them safely and delete only what you checked.
- Disk usage with du and ncduHow to find what fills a Linux disk with du and the interactive ncdu, with options that stay on one file system.
Sources
Last reviewed: