Ever gotten a disk full error, only to run
df and not see any full
disks? After banging you head against the wall for a while, you
remember to run
du -i and low an behold you are out of inodes.
What’s an inode anyway? It’s the data structure used to represent a filesystem object, that is the thing that stores the file name, file type, permissions, access and update times, and so on. Most UNIX filesystems allocate a fixed amount of space for inodes when they are created, setting an upper limit on the number of files, regardless of size, they can hold.
So, when you are out of inodes, it’s because your disk is full of
little files taking them up. But, how do you find them?1 If disk space
was the issue, you could us
du, but there is no inode equivalent.
The trick is to use
I got this particular version from
this Stack Exchange post
and it’s way cleaner than my old version that used
Let’s break it down:
/var is the filesystem we want to know about
find not to descend into other filesystems. If
/var/www is it’s own partition under /var,
-xdev causes it to be
-printf '%h\n' this is the secret sauce. By default,
print our all of the files in the filesystems, %h say to instead
print each file’s directory. 99.9% of the time when you run out of
inodes, all the little files that are using them up are in one
sort sorts the list of directory, which is needed so that:
uniq -c can do it’s job and count the number of times that each
directory appears in the list allowing:
sort -n to sort the results in numeric order from least files to most. Alternatively,
sort -nr | head would should you the 10 biggest offenders in descending order.
The output is a list of directories and the number of files each directory contains. And chances are the one(s) with the most files are your problem. Now, go clean them up.
Actually, when I run out of inodes, 99% of the time it’s on Ubuntu with auto updates are turned on and the problem is /usr/src/linux-headers-**. The headers are lots of little files. When auto updates are on, new kernels get installed along with their headers. Unless
sudo apt-get autoremoveis run they build up and steal all your inodes. This is also what fills up /boot*.↩