How to Free Inode Usage? How to Free Inode Usage? unix unix

How to Free Inode Usage?


If you are very unlucky you have used about 100% of all inodes and can't create the scipt.You can check this with df -ih.

Then this bash command may help you:

sudo find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n

And yes, this will take time, but you can locate the directory with the most files.


It's quite easy for a disk to have a large number of inodes used even if the disk is not very full.

An inode is allocated to a file so, if you have gazillions of files, all 1 byte each, you'll run out of inodes long before you run out of disk.

It's also possible that deleting files will not reduce the inode count if the files have multiple hard links. As I said, inodes belong to the file, not the directory entry. If a file has two directory entries linked to it, deleting one will not free the inode.

Additionally, you can delete a directory entry but, if a running process still has the file open, the inode won't be freed.

My initial advice would be to delete all the files you can, then reboot the box to ensure no processes are left holding the files open.

If you do that and you still have a problem, let us know.

By the way, if you're looking for the directories that contain lots of files, this script may help:

#!/bin/bash# count_em - count files in all subdirectories under current directory.echo 'echo $(ls -a "$1" | wc -l) $1' >/tmp/count_em_$$chmod 700 /tmp/count_em_$$find . -mount -type d -print0 | xargs -0 -n1 /tmp/count_em_$$ | sort -nrm -f /tmp/count_em_$$


My situation was that I was out of inodes and I had already deleted about everything I could.

$ df -iFilesystem     Inodes  IUsed  IFree IUse% Mounted on/dev/sda1      942080 507361     11  100% /

I am on an ubuntu 12.04LTS and could not remove the old linux kernels which took up about 400,000 inodes because apt was broken because of a missing package. And I couldn't install the new package because I was out of inodes so I was stuck.

I ended up deleting a few old linux kernels by hand to free up about 10,000 inodes

$ sudo rm -rf /usr/src/linux-headers-3.2.0-2*

This was enough to then let me install the missing package and fix my apt

$ sudo apt-get install linux-headers-3.2.0-76-generic-pae

and then remove the rest of the old linux kernels with apt

$ sudo apt-get autoremove

things are much better now

$ df -iFilesystem     Inodes  IUsed  IFree IUse% Mounted on/dev/sda1      942080 507361 434719   54% /