What's Eating All My Inodes?

One-liner for finding inode usage
October 22, 2016
filesystem linux inodes

Sometimes a script goes rogue and starts writing out little files. Today it was a cron job using wget that didn’t redirect the output. wget writes output to the filesystem with a file named after the URL. The next time it writes to it and appends .1 and then .2 and so on, until eventually it wraps and starts appending .1.1 and so on. Fast forward a few weeks and we get an alert that free inodes are < 20%.

This doesn’t happen often, so I end up searching for the same article on Stack Overflow and using the first solution. To save time in the future (though not as much time as I would save if I just aliased the command in my shell), I’m copying it here:

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

His solution shows all of the output and tells you to scroll to the bottom. Since I only care about the big offenders, my solution reverse sorts and shows you the top five consumers. Your problem will be within this list.

 276491 /root
   2966 /var/lib/dpkg/info
   2817 /usr/share/man/man3
   1377 /usr/src/linux-headers-3.13.0-96-generic/include/config
   1377 /usr/src/linux-headers-3.13.0-93-generic/include/config

Oops. 276k files like this:

./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.132538.1
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.109496
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.140574.1
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.83507.1
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.63857.1
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.100787.1
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.36781
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.48448.1
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.38579.1
./wp-cron.php?doing_wp_cron&fe095b3f6368d371f4ab9700e0744ff9.103353.1

To clean it up is easy:

find /root -type f -name wp-cron\* -delete