Dealing with “No space left on device” when partition is not full

When you get the “No space left on device” error on linux, first thing you do it to check your disk space usage.  Often times you notice you still have space, so what could be wrong?

Although your partition is not nearly full, most likely you have too many small or zero-sized files on your disk. So while you have enough disk space, all your available inodes have been exhausted. 

To check this run:
df -ih
If IUse percentage is at or near 100%, then huge number of small files is the reason for “No space left on device” errors.

To find out where inodes are being used run:
echo "Detailed Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"
After finding the directory with largest number of files, delete any unwanted files to free up some inodes. 

NOTE : If a process is using the files you are deleting, you will need a reboot to free the inodes used.