Best way to clear inodes?

October 18, 2014 6.8k views

I have run out of inodes! I have a folder with millions of smaller files that I would like to keep. However, using df -i I see that I am 100% out of inode space. Can I just clear them? It appears I need to do something since I can’t even download the files through scp or sftp in order to clear them from my remote server.

Ideas? Suggestions?

2 Answers

An inode is allocated at the file level so it’s quite possible to run out of inodes long before you run out of disk if you have millions of smaller files. If you are completely out of inodes, you’ll have to delete what you can. You’ll probably want to reboot in order to make sure there aren’t any processes holding onto the files in memory.

Obviously, this isn’t a long term solution. You’ll probably need to either use a bigger droplet or look into using and external storage component that you can mount as a network file system.

Your inodes are full, so there’s files somewhere in your server occupying them.

To find what’s consuming inode space, run this:

for i in /*; do echo $i; find $i |wc -l; done

After it returns the sizes of each item, look through them and see which directory is the biggest. Keep drilling down directories a few times until you found the culprit folder. It’s probably log files (error logs/admin logs), PHP session files, or in my case, mod cache disk. I had to keep going into the /var folder, show below.

for i in /var/*; do echo $i; find $i |wc -l; done

Once my search showed that /var/cache/apache2/modcachedisk was using almost 100% of my inodes, i deleted the folder and restarted apache and the server, making my inode usage only 4%, down from 100%.

service apache2 restart

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!