Fundamentals 9 min read

What Is an Inode? Understanding Linux File Metadata and Links

This article explains the concept of inodes in Unix/Linux filesystems, detailing their structure, stored metadata, size calculations, inode numbers, directory handling, hard and soft links, and the special behaviors that arise from separating file names from inode identifiers.

Liangxu Linux
Liangxu Linux
Liangxu Linux
What Is an Inode? Understanding Linux File Metadata and Links

What Is an Inode?

Files are stored on disk in sectors (512 bytes each). The OS reads multiple sectors at once as a block, typically 4 KB. Metadata about each file—owner, timestamps, permissions, etc.—is stored in a separate structure called an inode (index node). Every file has its own inode.

Inode Contents

File size in bytes

Owner User ID

Group ID

Read, write, execute permissions

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

Link count (how many directory entries point to this inode)

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

You can view an inode’s information with the stat example.txt command.

Inode Size

During formatting the disk is split into a data area and an inode table. Each inode typically occupies 128 bytes or 256 bytes. For a 1 GB disk with 128‑byte inodes and one inode per 1 KB, the inode table consumes about 128 MB (12.8% of the disk).

Check total and used inodes with df -i. To see the inode size on a device, run sudo dumpe2fs -h /dev/hda | grep "Inode size".

Inode Number

Each inode has a unique number used by the OS to identify files. The command ls -i example.txt displays the inode number associated with a file name.

Directory Files

In Unix/Linux a directory is also a file that contains a list of directory entries (dirents). Each entry stores a file name and its inode number.

List directory contents with ls /etc, show inode numbers with ls -i /etc, and view detailed information with ls -l /etc.

Hard Links

Multiple file names can point to the same inode, creating hard links. Changing the file through any name affects all names; deleting one name does not remove the data as long as at least one link remains. Create a hard link with ln source_file target_file. The inode’s link count increases, and when it drops to zero the inode and its data blocks are reclaimed.

Directories contain two default entries: “.” (the directory itself) and “..” (its parent). Consequently, a directory’s hard‑link count equals 2 plus the number of its sub‑directories.

Soft (Symbolic) Links

A symbolic (soft) link is a special file whose contents are the path to another file. The link has its own inode, but its data points to the target’s pathname. Deleting the target makes the soft link dangling, producing a “No such file or directory” error. Create a soft link with ln -s source_path target_path.

Special Effects of Inode Separation

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

Renaming or moving a file changes only the directory entry, not the inode number.

Running processes identify open files by inode, not by name, allowing software updates without stopping the program: a new version gets a new inode while the old one remains in use until the process exits.

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.

metadatainodeFilesystemHard Linksoft link
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.