Inode number is a unique identifier for files & directories in Linux. Every disk partition has a fixed number of inode numbers assigned when the partition is created. If your Linux system runs out of inode numbers then you will not be able to create new files & directories on it, even if there is disk space. Sometimes you may need to check inode usage on your disk. In this article, we will look at how to check inode usage in Linux.
How to Check Inode Usage in Linux
Inode is a data structure created when a new file/directory is created on your disk. It contains information about file such as access time, size, permissions, etc.
You can easily check inode usage using df -i command, as shown below. It will list inode usage of all disk partitions on your Linux system.
$ df -i / Filesystem Inodes IUsed IFree IUse% Mounted on /dev/xvda1 7692288 652294 7039994 9% /
In the above output, the column IUse% indicates the inode usage in Linux.
If you use Ext2/Ext3/Ext4 filesystem, you can also use tune2fs utility tool.
$ sudo tune2fs -l /dev/xvda1 | grep -Ei 'inode count|free inode' Inode count: 7782288 Free inodes: 7241110
That’s it. It is quite easy to get inode usage in Linux. If you want to regularly count inode usage on your system, you can simply create cronjob for it.
Open crontab with the following command.
$ crontab -e
Add the following line to run the df command everyday at 10.a.m and save the output in /home/inode_usage.txt
0 10 * * * sudo df-i >>/home/inode_usage.txt 2>&1
The above command simply runs the df command every day at 10.a.m and appends the output to /home/inode_usage.txt. So you just need to open inode_usage.txt and check the last entry to get latest inode usage of your disk. If you don’t want to append the result of above command but overwrite it everyday, then replace >> with >
0 10 * * * sudo df-i >/home/inode_usage.txt 2>&1
In this article, we have learnt how to count inode usage of your disk and also how to automate it using cronjob.