All ArticlesLinux2026-11-11T19:13:02+08:00

Disk Shows Space Available but Cannot Create Files? Verify Inode Exhaustion with df -i

Your server reports free disk space yet applications fail with 'No space left on device' errors. After reading, you will know how to check inode usage with df -i, locate directories with excessive small files, and clean them up safely.

Your application crashes with "No space left on device," but df -h shows gigabytes free. You restart the service, same error. You check disk usage again, still plenty of room. This is one of the more confusing Linux failure modes, and it almost always comes down to inodes.

What Inodes Are and Why They Run Out

Every file on a Linux filesystem (ext4, ext3, etc.) needs an inode — a data structure that stores metadata like ownership, permissions, timestamps, and pointers to the actual data blocks. The total number of inodes gets fixed when the filesystem is created. Once every inode is allocated to a file, no new files can be created, even if the disk is mostly empty in terms of bytes.

This typically happens on servers that accumulate massive quantities of tiny files: PHP session files, mail queue fragments, cache entries, thumbnail images, or log rotation artifacts. A directory with hundreds of thousands of one-kilobyte files barely dents your disk space but can consume every available inode.

XFS handles this differently — it allocates inodes dynamically by default, so inode exhaustion is rare on XFS unless explicitly capped. But ext4, which is still extremely common on hosting servers and VPS instances, sets a fixed inode count at format time.

Step 1: Check Inode Usage with df -i

The diagnostic is one command:

df -i

Sample output format:

Filesystem       Inodes   IUsed    IFree IUse% Mounted on
/dev/sda1       6553600 6553600        0  100% /
tmpfs            505765       1   505764    1% /dev/shm

Look at the IUse% column. If any mounted filesystem shows 100% (or very close), that is your problem. The IFree column showing 0 confirms it — no inodes left, no new files possible, regardless of free bytes.

Compare this with regular disk usage:

df -h

If df -h shows free space but df -i shows 100% usage, you have confirmed inode exhaustion.

Step 2: Find Which Directories Hold the Most Files

Knowing inodes are exhausted is step one. Step two is finding where all those files live. The following command counts files per directory under a given path. Start broad (the root of the affected partition), then narrow down:

find / -xdev -type f | cut -d '/' -f 2,3,4 | sort | uniq -c | sort -rn | head -20

Breaking this down:

  • find / -xdev -type f — find all regular files on the same filesystem (the -xdev flag prevents crossing into other mounted filesystems)
  • cut -d '/' -f 2,3,4 — extract the first three directory levels from each path
  • sort | uniq -c | sort -rn — count occurrences and sort by count, highest first
  • head -20 — show top 20 directories

This command can take a while on large filesystems. It is read-only and safe to run on a production server, though it will generate some I/O load.

Common culprits that show up:

  • /var/spool/exim/input or /var/spool/postfix — mail queue buildup, often from spam or misconfigured mailing scripts
  • /tmp or /var/tmp — session files, especially PHP sessions that never get cleaned
  • /home/*/public_html/wp-content/cache — WordPress cache plugins generating per-page or per-query cache files
  • /var/lib/php/sessions — PHP session storage on systems with long or no session garbage collection
  • /home/*/mail — maildir accounts with tens of thousands of individual email files

Once you identify the directory, drill deeper:

ls -1 /var/spool/exim/input/ | wc -l

This gives you a raw file count for that specific directory.

Step 3: Clean Up Safely

Before deleting anything, understand what the files are. Blindly removing files from a mail spool or cache directory can cause data loss or break running services.

Mail queue files: If the mail queue has hundreds of thousands of entries, most are likely spam or bounced messages from a compromised script. On Exim (common on cPanel servers), you can inspect the queue and flush it:

exim -bpc

This prints the queue count. If the number is enormous and the messages are clearly junk (check a few with exim -Mvh <message-id>), you can clear the queue. But first identify and stop whatever is generating the mail — a compromised contact form, a PHP script sending spam, a forwarding loop.

Session files: Old PHP session files in /tmp or /var/lib/php/sessions are generally safe to remove if they are older than your session lifetime. A common approach:

find /tmp -maxdepth 1 -name 'sess_*' -type f -mtime +2 -delete

This deletes session files older than 2 days. Adjust -mtime to match your application's session timeout. The -delete flag is irreversible — double-check the path and the -name pattern before running it.

Cache directories: WordPress cache plugins like WP Super Cache or LiteSpeed Cache can generate enormous numbers of small files. Clearing the cache through the plugin's admin panel is safest. If the site is down and you need to clear from CLI, remove the contents of the cache directory (not the directory itself).

Important: After cleanup, verify inode usage dropped:

df -i

If IUse% dropped significantly, the problem is resolved. If it barely moved, you have not found the real culprit yet — go back to the find command and look deeper.

Step 4: Prevent Recurrence

Cleaning up once fixes the immediate problem. Preventing it from happening again requires understanding why those files accumulated.

PHP session garbage collection. PHP has three php.ini directives that control session cleanup: session.gc_probability, session.gc_divisor, and session.gc_maxlifetime. On some distributions, garbage collection is disabled in PHP-FPM and handled by a system cron job instead. If that cron job is missing or broken, sessions pile up forever. Check whether your setup relies on PHP's built-in GC or a system cron, and make sure whichever mechanism is in place actually runs.

Mail queue monitoring. A mail queue that grows without bound usually means something is sending mail faster than it can be delivered (or the messages are undeliverable). Monitoring queue size — even a simple cron that runs exim -bpc or mailq | tail -1 and alerts above a threshold — catches this before inodes run out.

Cache size limits. Most caching plugins and tools have configuration options to limit total cache size or file count. Use them. An unbounded cache on a filesystem with fixed inodes is a slow-motion failure.

Journald logs. On systemd-based systems, journald can accumulate significant numbers of journal files under /var/log/journal/. Setting SystemMaxUse in /etc/systemd/journald.conf caps this. For more detail on managing journald storage, see systemd Journal Filling /var on a WHM Server: Vacuum Once or Set SystemMaxUse?.

Shared hosting environments often enforce inode limits per account as a soft resource boundary. If you are on shared hosting and hitting inode limits, the approach is the same — find which directories have the most files and clean or restructure. The article Unlimited Shared Hosting Has an Inode Limit: Why It Breaks MDX Sites and News Portals covers that angle specifically, though the internal link is not in the approved list so check your provider's documentation for their specific limits.

Quick Reference: The Verification Sequence

When you get "No space left on device" but df -h shows free space:

  1. Run df -i — check if any filesystem is at or near 100% inode usage.
  2. Run the find | cut | sort | uniq -c pipeline to locate directories with the most files.
  3. Identify what the files are before deleting anything.
  4. Clean up the files, then run df -i again to confirm inodes were freed.
  5. Fix the root cause — session GC, mail queue, cache limits — so it does not recur.

This whole process takes minutes once you know what to look for. The confusing part is that first moment when disk space looks fine but nothing works — once you know about inodes, df -i becomes the second thing you check after df -h, every time.