Learn more about Inode in Linux

Inodes are like ID cards for files on a Linux server—they store important details about each file. Your server has a fixed number of inodes, and every file you create uses one. If you run out of inodes, you might see disk space errors and other weird issues on your site, even if you have free storage.

An inode is a data structure that keeps track of all the files and directories within a Linux or UNIX-based filesystem. Inodes in Linux are unique IDs that keep track of files and folders in a system. Monitoring them is key to avoiding problems like running out of inodes or using too many.

An inode holds key details about a file, including:

  • File type (like a document, folder, or script)
  • File size
  • Owner and group information
  • Permissions (who can read, write, or run it)
  • Last accessed time
  • Last modified time
  • Last time its metadata was changed

Every file in Linux has a unique ID called an inode number. When you create or copy a file, the system gives it a new inode number. But if you move a file, its inode number stays the same—unless you move it to a different filesystem. This rule applies to folders too.

View my servers inodes

The total number of inodes in a filesystem can theoretically go up to around 4.3 billion, but what really matters is how many are available on your system. Typically, there’s one inode for every 16 KB of storage. You can check your inode count using the df -i command.

# df -i

Inode limit

The total number of inodes in a filesystem is set when it’s created and can’t be changed on the fly. That’s why it’s important to keep an eye on inode usage to make sure it stays within limits.

If you’ve ever tried to create a new file on a server and got an error—even though there’s plenty of free space—you might have hit the inode limit.

No space left on device

Running out of inodes before running out of disk space is rare but can happen. This usually occurs when:

  • Running containers.
  • Creating too many directories, symlinks, or tiny files.
  • Using ext3 filesystems with small block sizes.

High inode usage can cause serious problems, like:

  • Data loss
  • Server crashes or restarts
  • Applications failing
  • Scheduled tasks not running

To avoid these issues, keep inode usage low by regularly deleting:

  • Unneeded files and folders
  • Cache files
  • Old emails
  • Temporary files

Check a file’s inode number 

The stat command provides details about a file and its filesystem. You can use it to find the inode number of a file.

# stat /var/log/lastlog

You can use the ls command with the -i option to see a file’s inode number. This command displays the files and directories in the system.

# ls -i /var/log/lastlog

You can use the ls command with the -i option to find a directory’s inode number.

# ls -idl /var/log

The df command shows the total and available space on a filesystem. You can use it with the -i option to check inode usage.

# df -i /dev/sda1

The wc command helps count characters, words, lines, and bytes in a file. When used with the -l option, it can also count the number of inodes in a directory.

# find /var/log | wc -l

Leave a Reply

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