Skip to main content
FileSystems

Understanding inodes in Linux

By May 19, 2013September 12th, 2022No Comments

I am sure that there are many of us out there who accept that inodes exist but don’t fully understand how they work or why thy are there. In some respects if we are not writing drivers to the filesystem then maybe ignorance of these enigmas is OK; but the basics are not hard to grasp. In this video we would like to highlight the main point about inodes and how they interact.

Inodes don’t contain the filename

The first point that we should know is that the inode does not contain the filename. The filenames are part of the file-system along with inodes but are held in a separate table. The filename is stored with the inode number of the file and links to the files inode.

If we run the command ls or ls -i the only elements shown are the file name or the file name and inode number. This means all the information can be gained form just the filename table without reading from the inode table.

The idea of keeping the name separate from the inode makes indexing the filename easier as less data is stored and additionally the abilty to crate hard links; files with multiple names. Different filenames then can point to the single inode.

What do inodes hold?

Ok, so they do not contain the file name, what do the contain? Inodes contain metadata about the file.

  • the file data size
  • inode number
  • the number of links or filename that point to the inode
  • the mode or permissions of the file
  • the user owner of the file
  • the group owner of the file
  • additional flags
  • timestamps
  • pointer to the file data

We can use the stat command to view the metadata about a file or what we call the inode

stat <filename>

If we use the ls -l command then we see some of this information from the inode. We retrieve this information from both the inode table and the filename table.

Other tools

We may be familiar with the df command, but have you come across df -i . This will show how many inodes are used and are left available in filesystems. Likewise we will know the find command I am sure, so why not try:

find . -inum 131134

This will search for the file with the given inode number from the current directory down. This can be useful with the -delete action to remove a fie with weird characters in the name. The video shows you how.