Back to lessons

Hosting Operations

Find Directories Burning Inodes

Inode usage is high and you need to locate which directories contain the most regular files.

Command

find /lab/disk-inode-cleanup/var/cache/app -xdev -type f -printf '%h\n' | sort | uniq -c | sort -nr | head

What changed

Nothing changes. The command counts files by parent directory.

Danger

safe

When to use it

Use when df -ih is high and large-file searches do not explain write failures.

When not to use it

Do not assume the largest count is safe to delete; identify the application owner and cache semantics first.

Undo or recovery

No undo needed because this is a read-only file count.

Expected output

A count of regular files grouped by parent directory, sorted highest first.

demo script

Disposable terminal steps

  1. df -ih /lab/disk-inode-cleanup
  2. find /lab/disk-inode-cleanup/var/cache/app -xdev -type f -printf '%h\n' | sort | uniq -c | sort -nr | head

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ df -ih /lab/disk-inode-cleanup
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/vda1        512K  499K   13K   98% /lab/disk-inode-cleanup
tmpfs            245K    14  245K    1% /run
::exit-code::0
$ find /lab/disk-inode-cleanup/var/cache/app -xdev -type f -printf '%h\n' | sort | uniq -c | sort -nr | head
    120 /lab/disk-inode-cleanup/var/cache/app/shards/a
     40 /lab/disk-inode-cleanup/var/cache/app/shards/b
::exit-code::0

YouTube Short

Find inode hotspots.

When inodes are the problem, count files by directory. The biggest byte consumer may not be the inode culprit.

LinkedIn hook

Inode cleanup starts by finding the directory with too many files.

Question: Have you seen a small cache directory exhaust inodes before it exhausted bytes?

experiments

A/B tests to run

Metric: save_rate

A: Inodes are file count pressure.

B: Find the directory burning inodes.