Linux: Check Inode Usage

Objective: Get the inode usage count and the number of free inodes on a Linux system. Also learn how to find out the inode number of a file and search for a file using a inode number.

Inode is a data structure in a Unix-style filesystem that describes a file-system object such as a file or a directory. It may contain metadata information like file access time, permissions, etc.

Each filesystem or partition has its own set of inodes. To uniquely identify a file, you need both the inode and the device partition information.

If all the inodes in a filesystem are used up, the kernel can not create new files even when there is available free disk space. So, if you have ample free disk space but unable to create new files, check the inode usage for that partition.

To get the inode usage for the root partition using df, use the following syntax.

On ext2/ext3/ext4 filesystems, you can also use the tune2fs command.

Tips and Tricks using Inode

To get the inode of a file, ls command can be used. For example, to get the inode for the /etc/hosts file, use the following syntax.

The inode number for the /etc/hosts file is 3932325.

If you want to search for a file belonging to a specific inode, use the find command. Let’s do a reverse search for the /etc/hosts file using the inode number 3932325.

For the example above, we are telling find to search the root partition and not to descend to directories on other filesystems using the -xdev option. Without the -xdev option, find will check for a file with the specified inode number on all partitions.

If you are running out of inodes and need to determine which directory is hogging up most of the inodes, you can use the following syntax.

We can see from the output above that /var/lib/dpkg/info directory has about 9000 files. You can proceed to cleanup the directory or move the contents of that directory to another partition to free up the inodes.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }