How to Fix Inode Exhaustion Errors in Linux

An inode exhaustion error occurs when a Linux filesystem runs out of available index nodes, preventing the creation of new files even if physical storage space remains available. This article explains what inodes are, how inode exhaustion causes the misleading "No space left on device" error, how to diagnose the issue using Linux command-line utilities, and the exact steps required to locate and delete the excess files causing the problem.

What is an Inode and Inode Exhaustion?

An inode (index node) is a data structure on Unix-style filesystems that stores metadata about a file or directory, such as its size, ownership, permissions, and physical location on the disk, but not its content or filename.

When a standard filesystem (such as ext4) is created, a predetermined number of inodes is allocated based on the total drive capacity. Every file, directory, symlink, or socket consumes exactly one inode. Inode exhaustion happens when thousands or millions of tiny files—such as cache entries, temporary files, or email queues—consume all available inodes. When the inode table reaches 100% capacity, the operating system throws a "No space left on device" error, halting write operations, services, and system updates, even if df -h shows plenty of gigabytes remaining.

How to Diagnose Inode Exhaustion

To confirm whether an inode shortage is causing system errors, check the inode usage across all mounted filesystems:

df -i

Look at the IUse% column in the output:

Filesystem      Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1      3276800 3276800       0  100% /

If any filesystem displays an IUse% of 100%, that partition can no longer index new files.

How to Find Directories with the Most Inodes

Once the affected filesystem is identified, locate the specific directories storing millions of small files. Run the following command from the root or the mounted path to count files inside each top-level directory:

find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n

Alternatively, to scan directory-by-directory without heavy memory overhead, use:

for d in /*; do echo -n "$d: "; find "$d" -xdev | wc -l; done

Drill down into the directories reporting the highest counts. Typical culprits include:

Resolving Inode Exhaustion

1. Safely Delete the Excess Files

When a single directory contains hundreds of thousands of files, standard wildcards like rm -rf * fail with an Argument list too long error. Use find with the -delete action or xargs to process files in batches.

To delete older temporary session files:

find /var/lib/php/sessions -type f -name "sess_*" -delete

To delete files older than 7 days in a cache directory:

find /path/to/cache -type f -mtime +7 -delete

2. Clear Unused System and Package Files

On Debian/Ubuntu systems, old Linux kernels consume substantial inode allocations:

sudo apt-get autoremove --purge

On RHEL/CentOS systems:

sudo dnf autoremove

Clear package manager caches:

sudo apt-get clean      # Debian/Ubuntu
sudo dnf clean all      # RHEL/CentOS

How to Prevent Future Inode Exhaustion