Inodes in Linux: limit, usage and helpful commands

Inodes in Linux

Inodes in Linux are unique identifiers that describe files and directories within a filesystem. It is important to keep an eye on them to avoid issues related to inode shortage or excessive usage.

What is an inode?

An inode is a data structure that keeps track of all the files and directories within a Linux or UNIX-based filesystem. So, every file and directory in a filesystem is allocated an inode, which is identified by an integer known as “inode number”. These unique identifiers store metadata about each file and directory.

“Inode” is the abbreviation for “index node”.

All inodes within the same filesystem are unique. However, the same inode number can be used in different filesystems. Because the filesystem ID and each inode number are combined to create unique identification labels.

Metadata stored in an inode

Inodes store metadata such as:

  • File type
  • File size
  • Owner ID
  • Group ID
  • Read, write and execute permissions
  • Last access time
  • Last change time
  • Last modification time

Inode number: creating, copying and modifying files

As explained above, each inode is identified by an inode number. Therefore, when creating or copying a file, Linux assigns a different inode number to the new file. However, when moving a file, the inode number will only change if the file is moved to a different filesystem. This applies to directories as well.

Number of inodes in a filesystem

The theoretical total number of inodes in a system is approximately 4.3 billion. But the figure you should care about is the number of inodes in your system. The general ratio of inodes is 1:16 KB of system capacity. You can check the number of inodes in a filesystem using the df command with the -i option.

Let’s see why it is important to know the number of inodes in a filesystem.

Inode limit

The total number of inodes in a filesystem is defined when it is created and it cannot be changed dynamically. So, it is important to regularly check inode usage to guarantee it adjusts to the configured limits

If you have ever got the following error message when trying to create a new file on a server — even though you know there is plenty of space still available —, you might have reached the inode limit of your system:

No space left on device

Although it is unusual to run out of inodes before running out of actual disk space, it is not impossible. It can happen when: 

  • Using containerization.
  • Creating lots of directories, symbolic links and small files.
  • Creating ext3 filesystems with smaller block sizes.

Inode usage issues and best practices

An excessive inode usage can lead to issues when creating new files and directories. Some of the issues users may encounter when the server runs out of inodes are:

  • Data loss.
  • Server restart.
  • Application crash.
  • Scheduled tasks not running.

So, it is recommended to keep inode usage low by deleting:

  • Unnecessary files and directories.
  • Cache files.
  • Old email files.
  • Temporary files.

Helpful commands

Check a file’s inode number 

Using the stat command

The stat command gives information about the file and filesystem. So, you can use it to check the inode number of a file.

[root@stackscale ~]$ stat /var/log/lastlog

When executing the command, you will get the following information:

File: /var/log/lastlog
Size: 292292     Blocks: 96 IO Block: 4096 regular file
Device: fd00h/64768d    Inode: 17381397 Links: 1
Access: (0664/rw-rw-r-) Uid: ( 0/ root) Gid: ( 22/ utmp)
Context: system_u:object_r:lastlog_t:s0
Access: 2022-01-12 11:28:19.900058928 +0100
Modify: 2022-01-12 11:28:19.900058928 +0100
Change: 2022-01-12 11:28:19.900058928 +0100
Birth: 2021-06-25 17:40:57.254208200 +0200

Using the ls command

You can also use the ls command, together with the -i option, to get a file’s inode number. This command lists files and directories within the filesystem.

[root@stackscale ~]$ ls -i /var/log/lastlog
17381397 /var/log/lastlog

Check a directory’s inode number using the ls command

You can also use the ls command and the -i option to get a directory’s inode number. For doing so, you need to add a few more options.

[root@stackscale ~]$ ls -idl /var/log
16813380 drwxr-xr-x. 18 root root 4096 Jun 6 12:33 /var/log

Check inode usage within a filesystem using the df command

The df command is used to display information related to a filesystem’s total and available space. So, you can use it, together with the -i option, to control inode usage in filesystems.

[root@stackscale~]$ df -i /dev/sda1
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 524288 379 523909 1% /boot

Check the number of inodes in a directory using the wc command

The wc command is used to count the number of characters, words, lines and bytes of files. Together with the -l option, you can use it to count the number of inodes in a directory.

[root@stackscale]# find /var/log | wc -l
120

Need help with system administration? We can help you.

Share it on Social Media!

Managed services

Partial or full system administration service, with 24/7 system monitoring, every day of the year.

DISCOVER MORE