Linux Inodes: What They Are and How They Work

When working with Linux, most administrators become familiar with commands like ls, df, du, and find. These tools help us navigate filesystems, monitor disk usage, and troubleshoot storage issues.

However, there’s another fundamental concept behind nearly every filesystem operation: the inode.

Understanding inodes is essential for troubleshooting disk space issues, understanding file permissions, working with hard links, and diagnosing situations where a filesystem behaves unexpectedly.

Let’s explore what inodes are, how they work, and how to use them effectively.

What Is an Inode?

An inode (short for index node) is a data structure used by Unix-like filesystems to store information about a filesystem object.

Every file, directory, symbolic link, and many other filesystem objects have an associated inode.

An inode stores metadata such as:

  • File type
  • Permissions
  • Owner and group
  • File size
  • Timestamps
  • Number of hard links
  • Pointers or references to the data blocks containing the file’s contents
  • Extended attributes

One important detail: an inode does not store the filename.

Instead, filenames are stored in directory entries, which associate a name with an inode number. When Linux accesses a file, it resolves the filename through the directory structure to locate the associated inode and then uses that inode to access the file’s metadata and contents.

This separation between filenames and inodes is what makes features such as hard links possible.

How Inodes Work

Think of a filesystem as having two primary components involved in accessing a file:

ComponentPurpose
Directory entryMaps a filename to an inode number
InodeStores metadata and references to the file’s data
Data blocksStore the actual contents of the file

For example, imagine the following file:

/home/aaron/Documents/notes.txt

The directory entry for notes.txt points to an inode number. That inode contains the metadata associated with the file and references the storage blocks where its contents reside.

We can examine this relationship using the ls command:

ls -i /home/aaron/Documents/notes.txt

Example output:

1234567 notes.txt

The number 1234567 is the inode number.
To examine the metadata associated with that inode, use stat:

stat /home/aaron/Documents/notes.txt

Example output:

  File: notes.txt
  Size: 1024       Blocks: 8          IO Block: 4096   regular file
Device: 8,1        Inode: 1234567    Links: 1
Access: (0644/-rw-r--r--)  Uid: (1000/aaron)  Gid: (1000/aaron)
Access: 2026-11-04 10:30:00.000000000 -0600
Modify: 2026-11-04 10:25:00.000000000 -0600
Change: 2026-11-04 10:25:00.000000000 -0600

Notice the Inode, Links, Size, and timestamp fields.

These values provide useful information when troubleshooting filesystem behavior.

Understanding Inode Numbers

An inode number uniquely identifies an inode within a particular filesystem.

This distinction matters because two different filesystems can contain files with the same inode number.

To list inode numbers for files in a directory:

ls -i

To list inode numbers recursively:

ls -iR /var/log

To display inode numbers alongside detailed file information:

ls -li

You can also retrieve the inode number of a specific file using stat:

stat -c '%i %n' /etc/hostname

Example:

987654 /etc/hostname

These commands are particularly useful when investigating duplicate filenames, hard links, and filesystem issues.

Inodes and Hard Links

One of the most interesting features of inodes is how they enable hard links.

A hard link is another directory entry that references the same inode as an existing file.

Consider this example:

echo "Hello Linux" > original.txt
ln original.txt hardlink.txt

Now examine both files:

ls -li original.txt hardlink.txt

Example output:

1234567 -rw-r--r-- 2 aaron aaron 12 Nov  4 10:30 original.txt
1234567 -rw-r--r-- 2 aaron aaron 12 Nov  4 10:30 hardlink.txt

Both filenames reference the same inode: 1234567.
The link count is now 2, indicating that two directory entries reference that inode.

If we modify one file:

echo "Additional content" >> hardlink.txt

The changes are visible through the other filename as well:

cat original.txt

Both names refer to the same underlying file object.

What Happens When You Delete a Hard Link?

Let’s remove one of the filenames:

rm original.txt

The inode still exists because another hard link references it.

cat hardlink.txt

The contents remain accessible.

The underlying data is eventually released when the inode’s link count reaches zero and no process still has the file open.

This is an important distinction: removing a filename does not necessarily mean removing the underlying file data.

Inodes and Symbolic Links

Symbolic links (symlinks) work differently from hard links.

A symbolic link is a separate filesystem object with its own inode. Its contents identify the pathname of another file or directory.

Create a symbolic link:

ln -s original.txt symlink.txt

Examine the inode numbers:

ls -li original.txt symlink.txt

Example:

1234567 -rw-r--r-- 1 aaron aaron 12 Nov  4 10:30 original.txt
7654321 lrwxrwxrwx 1 aaron aaron 11 Nov  4 10:31 symlink.txt -> original.txt

Notice that the inode numbers are different.

The symbolic link has its own inode, while its contents point to the target pathname.
This difference has practical consequences:

FeatureHard LinkSymbolic Link
Shares the target inodeYesNo
Has its own inodeNo (not a separate inode for the link)Yes
Can cross filesystem boundariesNoYes
Can point to a directoryGenerally prohibitedYes
Can become broken if target is removedNoYes

Disk Space vs. Inode Availability

One of the most important reasons to understand inodes is filesystem troubleshooting.

Linux filesystems generally track two separate resources:

  1. Data blocks: The storage capacity used to hold file contents.
  2. Inodes: The filesystem structures used to represent files and other objects.

These resources are allocated independently.

This means a filesystem can have plenty of free disk space but no available inodes.

Checking Disk Space

Use:

df -h

Example:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       50G   35G   15G  70% /

This reports storage capacity in a human-readable format.

Checking Inode Availability

Use:

df -i

Example:

Filesystem      Inodes  IUsed  IFree IUse% Mounted on
/dev/sda2     3276800 3276790     10  100% /

Here, the filesystem has available storage capacity but has exhausted its inode allocation.
The result?

You may be unable to create new files or directories even though df -h reports free space.

This is commonly caused by applications generating large numbers of small files, such as:

  • Application caches
  • Temporary files
  • Session files
  • Mail queues
  • Container storage layers
  • Build artifacts
  • Monitoring and logging systems

When troubleshooting filesystem issues, always check both df -h and df -i.

Troubleshooting Inode Exhaustion

If a filesystem has exhausted its available inodes, the next step is identifying where the large number of files are located.

The following command counts files and directories under a specified path:

find /var -xdev | wc -l

The -xdev option prevents find from traversing into other filesystems mounted beneath /var.

To identify directories containing large numbers of entries, you can use:

find /var -xdev -type d -exec sh -c '
    count=$(find "$1" -mindepth 1 -maxdepth 1 | wc -l)
    printf "%8s %s\n" "$count" "$1"
' sh {} \; | sort -nr | head -20

This helps identify directories that may contain excessive numbers of files.

For example, you might discover that an application is generating millions of temporary files under:

/var/lib/application/cache/

Once the source is identified, you can investigate whether the files are necessary, whether the application is behaving correctly, and whether a cleanup strategy is appropriate.

Important: Avoid blindly deleting files to recover inodes. Always identify what is consuming them before performing cleanup.

A Special Case: Deleted Files Still Consuming Disk Space

Another common Linux troubleshooting scenario involves files that have been deleted but continue consuming disk space.

This happens when a process still has the deleted file open.

When a file is deleted, Linux removes its directory entry. However, the inode and associated data blocks remain allocated while a process continues to reference the file.

This situation is particularly common with log files.

Imagine a large application log:

/var/log/application.log

You delete it:

rm /var/log/application.log

But df -h still reports that the filesystem is nearly full.

Why?

The application may still have the file open.

To identify deleted files that remain open:

sudo lsof +L1

Look for files marked (deleted).

You may find something similar to:

COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF NLINK NAME
app       1234 root    3w   REG  8,1    10G      0    /var/log/application.log (deleted)

The file’s link count is zero, but the process still holds a reference to the inode.

The usual resolution is to restart or otherwise safely release the process’s file handle. The disk space will then be reclaimed.

This is another excellent example of why understanding inodes is valuable in real-world Linux administration.

Are Inodes the Same Across Filesystems?

No.

An inode number is only guaranteed to be unique within its own filesystem.

For example:

ls -i /etc/hostname
ls -i /home/aaron/Documents/notes.txt

Both files could theoretically have the same inode number if they reside on different filesystems.

When identifying files by inode number, include the filesystem or device as part of the identification.

This is also why hard links cannot cross filesystem boundaries: the inode number alone cannot uniquely identify a file across multiple filesystems.

Practical Inode Commands Cheat Sheet

Here are some useful commands to keep in your Linux troubleshooting toolkit.

CommandPurpose
ls -iDisplay inode numbers
ls -liDisplay inode numbers with detailed file information
stat filenameDisplay file metadata, including inode
stat -c '%i %n' filenameDisplay inode number and filename
df -hCheck filesystem disk space
df -iCheck inode utilization
find /path -xdev | wc -lCount filesystem entries beneath a path
find /path -inum 1234567Find entries matching an inode number
ln source destinationCreate a hard link
ln -s source destinationCreate a symbolic link
sudo lsof +L1Find open files with no remaining directory links

Final Thoughts

Inodes are a fundamental component of Linux filesystem architecture. Although they are largely invisible during everyday file operations, they play a critical role in how files are stored, accessed, linked, and managed.

Understanding inodes gives Linux administrators a better foundation for troubleshooting filesystem behavior, diagnosing storage exhaustion, understanding hard and symbolic links, and investigating files that remain open after deletion.

The next time a Linux filesystem refuses to create a file despite having plenty of free space, remember to check inode utilization.

df -h
df -i

Sometimes, the problem isn’t a lack of disk space. It’s a lack of inodes.


Leave a Reply

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