Technical Anshu
Tutorials Blog

Every file and folder uses one inode. A filesystem can exhaust inodes long before it exhausts bytes - classic offenders are old PHP session files, mail spools, cache folders, node_modules trees, and log or tmp directories that were never cleaned. The diagnostic split is simple: df -h measures bytes, df -i measures inodes. If bytes are free and inodes are at 100%, no amount of deleting large files will help - you must delete many small files.

Terminal · df -i
$ df -i
Filesystem Inodes IUsed IFree IUse%
/dev/sda2 3276800 3276800 0 100% /

X Writes fail with No space left on device while df -h shows free space

X Creating even an empty file fails: touch test returns the same error

X The machine holds a web server, mail, or years of accumulated cache and tmp files

X df -i shows IUse% at 100% on the affected filesystem

INODES 100%  Bytes are free, file entries are not. The cure is deleting huge counts of small files, not big ones.

The fingerprint of this problem: df and df -i disagree - always trust df -i for this error.

Before you start: deleting millions of files with a careless rm -rf on the wrong folder is unrecoverable. Work directory by directory with the counting commands below, confirm each target, and never delete inside /proc, /sys, or a folder you have not identified first.
1

Confirm It Is Inodes, Not Bytes

One command pair settles the diagnosis and stops you deleting the wrong things.

  1. Run df -h / and df -i / side by side (replace / with the affected mount if different).
  2. If IUse% is 100% while bytes are free, it is inode exhaustion - continue. If both are full, you have an ordinary full disk instead.
  3. Note the exact filesystem - on servers /var or /home is often a separate mount with its own inode table.
2

Find Which Directory Holds the Millions of Files ⭐

Do not guess. Count inodes per directory and drill down level by level. ⭐

  1. Count the top level: sudo du --inodes -x / 2>/dev/null | sort -n | tail -20 - the largest counts are at the bottom.
  2. Drill into the biggest folder, for example: sudo du --inodes -x /var 2>/dev/null | sort -n | tail -20, and repeat until you reach the real offender.
  3. Common final answers: /var/lib/php/sessions or a session folder, /tmp, a mail queue, a user cache, or an old backup made of tiny files.
  4. Counting can take a few minutes on a loaded server - that is normal; let it finish rather than interrupting halfway.
3

Clear the Usual Offenders Safely

Clear contents, not the folders themselves, and prefer the tool each system already provides.

  1. Old sessions (confirm the path from Fix 2 first): files older than a day in a dedicated session folder can be removed with a find command scoped to that exact folder.
  2. Mail and print queues: check mailq and clear only stuck or ancient items through the mail tool, not by deleting spool files blind.
  3. Caches in a home folder: rm -rf ~/.cache/* is safe for the current user - caches rebuild themselves.
  4. System temp with systemd: sudo systemd-tmpfiles --clean applies the configured age rules instead of you guessing.
4

Check for Deleted Files Still Held Open

A process holding a huge deleted log keeps both its bytes and its inode alive - invisible to du, visible to lsof.

  1. Run sudo lsof +L1 and look for lines marked (deleted) with large sizes.
  2. Restart the service that owns the process (for example sudo systemctl restart <service>) - closing the handle releases the space and inode immediately.
  3. This is also why a disk can look full after you already deleted the log: deletion only frees the file when no process holds it open.
5

Verify the Fix and Prevent a Repeat

Confirm the table has room again, then remove the cause, not just the symptom.

  1. Re-run df -i / - IUse% should be well below 100% and a test touch ~/inode-test && rm ~/inode-test should succeed.
  2. Find out why sessions or tmp files were never cleaned: check that the session garbage-collection or tmpfiles timer is enabled for your stack.
  3. On a server you control, monitor inode use alongside disk use - alert on df -i, not only df -h, so this never surprises you again.
Do not do this: do not try to fix inode exhaustion by deleting a few large files - one large file frees exactly one inode. Do not run a blanket rm -rf /tmp/* on a live multi-user server without checking what active programs keep there. And do not reformat or recreate a filesystem to get more inodes as a first move - that erases everything and is only a last resort on a backed-up, rebuilt system.

More PC Fixes on Technical Anshu

Every week: Windows problems, hidden tools and full setup guides, explained step by step.

Subscribe on YouTube

Frequently Asked Questions

Why does Linux say No space left on device when df shows free space?

Because there are two limits: total bytes and total inodes. df -h shows bytes; df -i shows inodes. Millions of tiny files - sessions, mail, cache entries - can use every inode while gigabytes remain free. When inodes hit 100 percent, creating any new file fails with No space left on device.

How do I find which folder used all the inodes?

Count inodes per directory and drill down: sudo du --inodes -x / 2&gt;/dev/null | sort -n | tail -20, then repeat inside the largest folder such as /var. Typical offenders are PHP session folders, /tmp, mail spools, caches, and folders with millions of small backup or node files.

Does deleting one big file help an inode problem?

Almost not at all. One file, however large, uses one inode, so deleting it frees one entry. An inode fix requires deleting large numbers of small files in the offending directory, or releasing deleted-but-open files held by a process, which lsof +L1 reveals.

What are deleted but open files and why do they waste space?

When a process still has a deleted file open, Linux keeps its data and inode until the process closes it. A service holding a deleted multi-gigabyte log is the classic case. Find it with sudo lsof +L1 and restart that service to release the handle and free the space immediately.

Can I increase the number of inodes on a filesystem?

Not on a mounted, in-use ext filesystem - the inode count is set when the filesystem is created. The practical fixes are clearing the small-file buildup, fixing the cleanup job that failed, and, only on a planned rebuild with full backups, recreating the filesystem with a higher inode ratio.

Guide by Technical Anshu · Problem collected from Server Fault and Reddit user reports of No space left on device with free disk space; solution written in original words and verified against the df and lsof man pages and Ubuntu server documentation on inode exhaustion, verified on 11 November 2026. No matching long video exists on the channel for this exact fix, so this blog has no video section - the topic joins the fresh video-topic bank. No Shorts are linked in this blog.