inode usage count in Linux
Filed under tips & tricks on may 14, 2010
Filesystems like extfs use inodes to allocate blocks of (file) data. One can not only run out of disk space, but also out of inodes. You can use this to determine the number of inodes used in a directory:
~% find $HOME -type d -exec stat --format '%h' {} \; | awk '{s+=$1} END {print s}'
74
Or multiple directories:
/usr/share% for DIR in *; do
> printf "%8s %s\n" \
> $(find $DIR -type d -exec stat --format '%h' {} \; | awk '{s+=$1} END {print s}') $DIR
> done | sort -nr | head
4589 doc
2114 pyshared
941 icons
614 locale
404 perl5
389 perl
272 man
266 X11
230 vim
206 zoneinfo
You could stick this into your ~/.bash_profile:
di() {
for DIR in $1/*
do
if [ -d "$DIR" ]
then
printf "%8s %s\n" \
$(find "$DIR" -type d -exec stat --format '%h' {} \; | awk '{s+=$1} END {print s}') \
"$DIR"
fi
done
}
Now issue di /path/to/files to see the inode usage:
~% di /boot
2 /boot/grub
2 /boot/lost+found
You can ask df about the total inode usage of a filesystem:
~% df -i / Filesystem Inodes IUsed IFree IUse% Mounted on /dev/md1 2444624 156037 2288587 7% /
Post your feedback
You can use this form to leave your feedback. Your insights are always appreciated.