Just a quick way to look at Inode Counts
Luke Hebert
- 2 minutes read - 290 wordsRunning out of inodes is one of those sneaky Linux problems that catches you off guard. Your df output shows plenty of free space, yet writes fail with “No space left on device.” The culprit is inode exhaustion, and the fastest way to find the offender is a single bash pipeline.
The One-Liner
find -maxdepth 1 -type d | while read dir; do echo -en "$dir - "; find "$dir" | wc -l; done | sed 's/^\.\///' | column -t | sort -rnk3 | head -n10What It Does
find -maxdepth 1 -type dlists every directory at the current level.- The
whileloop counts all inodes (files, subdirectories, symlinks) inside each directory withfind "$dir" | wc -l. sed 's/^\.\///'strips the leading./so the output reads cleanly.column -taligns the results into a tidy table.sort -rnk3sorts numerically in reverse order by the third column (the count).head -n10keeps only the top ten offenders.
When to Use It
- You see
ENOSPCerrors butdf -hreports free blocks. - A service refuses to create new files or logs.
- You want a quick audit before running
find / -xdev -printf '%i\n' | sort -n | uniq -c | sort -rn | headfor a full filesystem scan.
Tips
- Run it from the mount point you suspect (e.g.,
cd /varbefore executing) to keep the scan fast. - If a single directory dominates, drill into it by
cd-ing there and re-running the same command. - Pair the results with
df -ito confirm the inode usage percentage for the affected filesystem.
Note
The find "$dir" | wc -l approach counts every entry, including subdirectories. For a true file-only count, swap in find "$dir" -type f | wc -l.