Disk space issue in Linux
Sometimes there’s plenty of free space on disk, but files stubbornly refuse to get created. In some cases you get an error saying the disk ran out of free space.
You keep typing:
df -ha
And you can’t figure out what’s wrong: there’s still a hundred gigs free on disk, yet you can’t create a file.
The -i flag shows info about available inodes:
df -i
Every file and folder on disk has a companion object that holds additional info about the file. In linux these companions are called inodes (inodes)
Every file and folder has permissions, owners, creation and modification times. That’s the info stored in inodes.
As a rule, most users don’t know the number of inodes is limited until they run into problems.
The more files created on disk, the more inodes get used to store info about them.
You can count all inodes used in the current directory with this script:
echo "Inode Usage BreakDown: $(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"
Unfortunately the inode count can’t be increased without recreating the filesystem, so you’ve got a problem if the server has only one partition. You can set the inode count with the -N flag of the mke2fs utility.