How to Check Inode Usage in Linux

When a file or a directory is created in a Linux file system, a name and a uniq inode number is assigned to it.

An inode is a data structure that contains information about a disk block location of a file or a directory and may include metadata (times of last change, access, modification), as well as information about the owner and permissions.

The number of inodes is defined during the file system creation and can’t be increased without reformatting the partition.

In this note i will show how to check the inode usage in Linux, how to list top directories sorted by inode usage and how to show the inode number of a file or a directory.

Check Inodes in Linux

No space left on device: The number of inodes within a file system directly affects the number of files i.e. the maximum number of inodes equals the maximum number of files that can be created. So if you have received the “No space left on device” error but the disk space isn’t really full – check the inodes!

To check the inode usage in Linux, use the df command with the -i, --inodes option:

$ df -i

Total inode usage of the root partition (in the -h, --human-readable format):

$ df -ih /
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/sda1        4.9M   71K  4.9M    2% /

If your Linux system is running out of inodes, and you wonder where they have being used, you can check the top inode usage per directory as follows:

$ { find / -xdev -printf '%h\n' | sort | uniq -c | sort -rn; } 2>/dev/null | head

The command above shows top 10 directories with the most number of files.

To find the file’s inode number in Linux, use the ls command:

$ ls -li /etc/fstab 
70891 -rw-r--r-- 1 root root 147 Jun 17 16:09 /etc/fstab

You can also check the inode number of a file or a directory, using the stat commands:

$ stat /etc/fstab
  File: /etc/fstab
  Size: 147       	Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d	Inode: 70891       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-06-17 16:09:32.867431626 +0000
Modify: 2021-06-17 16:09:33.043519633 +0000
Change: 2021-06-17 16:09:33.043519633 +0000
 Birth: -