Fundamentals 11 min read

What Is an inode? Uncover the Hidden Structure Behind Linux Files

This article explains the concept of inodes, their contents, size, numbering, relationship with directories, hard and soft links, special behaviors in Unix/Linux, and provides a real‑world troubleshooting example for inode exhaustion.

Open Source Linux
Open Source Linux
Open Source Linux
What Is an inode? Uncover the Hidden Structure Behind Linux Files

1. What is an inode

Understanding inodes starts with how files are stored.

Files are stored on a hard‑disk in the smallest unit called a sector, typically 512 bytes. The OS reads data in larger units called blocks (commonly 4 KB, i.e., eight sectors).

Metadata about a file—owner, timestamps, size, etc.—is stored in a structure called an inode (index node).

2. Contents of an inode

An inode holds the following metadata:

File size in bytes

User ID of the owner

Group ID

Read, write, and execute permissions

Three timestamps: ctime (inode change), mtime (content change), atime (last access)

Link count (number of directory entries pointing to the inode)

Locations of the data blocks that contain the file’s contents

Use stat to view an inode’s information.

3. Size of an inode

During formatting the disk is split into a data area and an inode table. Each inode typically occupies 128 bytes or 256 bytes. The total number of inodes is fixed at format time (e.g., one inode per 1 KB or 2 KB of disk space).

On a 1 GB disk with 128‑byte inodes and one inode per 1 KB, the inode table would consume about 128 MB (12.8% of the disk).

Use df to see inode usage per partition.
Use df -i to view inode counts and stat -f -c "%i" /path to see inode size.

Note: If all inodes are used, new files cannot be created even if free space remains.

4. Inode numbers

Each inode has a unique number; the OS uses this number to identify files, not the filename. The lookup process involves:

Finding the inode number associated with a filename.

Retrieving the inode’s metadata.

Locating the data blocks and reading the file’s contents.

Use ls -i to display inode numbers.

5. Directory files

In Unix/Linux a directory is also a file that contains a list of directory entries (dirents), each consisting of a filename and its corresponding inode number.

6. Hard links

Normally one filename maps to one inode, but multiple filenames can point to the same inode, creating a hard link . Changes to the file affect all hard‑linked names, and the inode is only freed when its link count drops to zero.

Create a hard link with ln source target .
ln source_file target_file

When a hard link is removed, the link count decreases; when it reaches zero, the inode and its data blocks are reclaimed.

7. Soft (symbolic) links

A soft link (symbolic link) is a special file that contains a pathname to another file. Deleting the target leaves the soft link dangling, producing a “No such file or directory” error.

Create a soft link with ln -s source target .
ln -s source_path target_path

8. Special effects of inode separation

Files with problematic names can be removed by deleting their inode directly.

Renaming or moving a file only changes the directory entry; the inode number stays the same.

Running processes keep the inode open, allowing updates without restarting services; a new version gets a new inode while the old one is reclaimed later.

9. Practical problem: inode exhaustion

On a low‑spec Linux server, creating files in /data failed despite 12 GB free space; df -i showed 100% inode usage.

Cause

Many tiny cache files in /data/cache consumed a large number of inodes.

Solution

Delete some files in /data/cache to free inodes.

Link a directory on a partition with free inodes (e.g., /opt/newcache) to /data/cache using a soft link:

ln -s /opt/newcache /data/cache
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxfile systeminodeHard Linksoft linkFilesystem Fundamentals
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.