How to count Inode usage in Linux?

We all know that everything is a file in Linux.

Each and every file & folder is considered as inode, which includes normal file, directory, link file, block file, device file, etc.

Each file or directory adds 1 to the inode count.

In this article, we will show you how to check the inode number of files and how to calculate the inode usage for a particular user.

What is Inode?

The inode stands for index node or index number. It is a data structure in a Linux file system that stores information about a file and directory.

File system generally consist of two parts, which are metadata and actual data.

Every file has a unique inode number that contains metadata about the file and the inode numbers will be unique only within the same file system.

You might get the following error when inode is full on the file system:

No space left on device or running out of Inodes.

Inode stores the following information about a file.

  • Size of the file.
  • Device ID
  • User ID (UID)
  • Group ID (GID)
  • Information about permissions (read, write, execute, etc)
  • File access privileges (owner, group and others)
  • Time stamps information such as file access, file modification, file deletion and inode number change.
  • Information about soft links and hard links
  • Location of the file on the file system

How to check Inode number of the file

Use ls command with -i option to view the inode number of the file, which can be found in the first field of the output.

# ls -li 2daygeek.txt

1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 2daygeek.txt

Searching a file using Inode number

Normally, we use a file name or other parameters to find a file, but this can be done using the inode number as well. Use the following format to search a file using its inode number.

# find /home/daygeek/ -inum 1740436


Checking Inode usage of file system

Use the following command to check the inode usage of active file system on your system.

# df -i

Filesystem       Inodes   IUsed    IFree IUse% Mounted on
/dev/vda1      13640832 1487624 12153208   11% /
devtmpfs         232604     326   232278    1% /dev
tmpfs            235277       1   235276    1% /dev/shm
tmpfs            235277     555   234722    1% /run
tmpfs            235277      16   235261    1% /sys/fs/cgroup
/dev/loop0       146592     139   146453    1% /tmp
tmpfs            235277       1   235276    1% /run/user/0

How to count Inode usage

If you would like to count inode utilization in the current directory, use the following command. This will print the output without grand total.

# pwd

# find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn
  43113 ./.cache
  16491 ./.rustup
   4057 ./.mozilla
   3257 ./Documents
   3054 ./.local
   1869 ./.config
   1567 ./.npm
   1551 ./Videos
    964 ./.cargo
    249 ./Pictures
    185 ./Downloads
    177 ./.bundle
    158 ./yay
    155 ./Desktop
    145 ./snap
    139 ./batstat

Counting Inode usage with grand total

If you would like to count inode utilization in the current directory, use the following command. This will print the output with grand total.

# echo "Detailed Inode usage for: $(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"

Detailed Inode usage for: /home/daygeek
11		- 2g
46		- bash-insulter
140		- batstat
96		- betty
178		- .bundle
43114		- .cache
965		- .cargo
1870		- .config
156		- Desktop
3258		- Documents
186		- Downloads
60		- drivesync
3055		- .local
4058		- .mozilla
1568		- .npm
250		- Pictures
16492		- .rustup
146		- snap
64		- ssh-audit
1552		- Videos
159		- yay

Total: 		77682

Checking Inode changes with ‘mv’ command

Inode values aren’t changed or modified when the file is moved within the file system. See the output below:

# ls -li /home/daygeek/2daygeek.txt 
1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 /home/daygeek/2daygeek.txt

# mv /home/daygeek/2daygeek.txt /home/daygeek/Downloads/

# ls -li /home/daygeek/Downloads/2daygeek.txt
1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 /home/daygeek/Downloads/2daygeek.txt

Checking Inode changes with ‘copy’ command

Inode values get changed or modified when the file is copied to another location. See the results below (a copy of the file is created in another location with a different name):

# ls -li /home/daygeek/Downloads/2daygeek.txt
1740436 -rw-r--r-- 1 daygeek daygeek 211 Feb 10 08:03 /home/daygeek/Downloads/2daygeek.txt

# cp /home/daygeek/Downloads/2daygeek.txt /home/daygeek/Downloads/2daygeek-new.txt

# ls -li /home/daygeek/Downloads/2daygeek-new.txt
1743316 -rw-r--r-- 1 daygeek daygeek 211 Apr  5 09:51 /home/daygeek/Downloads/2daygeek-new.txt

How to reduce Inode usage

The only option is to delete the unused files to reduce inode usage in Linux.

Bonus Tips for website owners

Most of the hosting providers claim to offer a Shared UNLIMITED hosting.

Is it true? No, it’s not! Because there is no way to offer such a service. Every web hoster have some Terms & Condition for INODE limits, so have a look at it before you buy their hosting.

If shared hosting is not suitable for you then try Virtual Private Server (VPS) or Dedicated Server (DS), because these are dedicated environment, which allows you to use complete storage and there is no restriction for inode usage as well.

Closing Notes

In this guide, we have explained how to count inode usage in Linux.

If you have any questions or feedback, feel free to comment below.

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

4 Comments on “How to count Inode usage in Linux?”

  1. Thanks for this, very useful!
    Any way to run any of the above as cron job with results to be sent by email?

    I’m using something similar already for counting storage space but don’t know how to adapt it for inaodes.

  2. I found that the counting does not work properly when the directory name has a space in it, then it just attempts to cut the first part of the directory name – before the space – and fails. I assume it has to deal with: **cut -d\/** as it is cutting exactly there..

  3. Useful information. Fortunate me I discovered your site by accident, and I’m stunned why this coincidence didn’t took place in advance! I bookmarked it.

Leave a Reply

Your email address will not be published. Required fields are marked *