What Is an inode? A Deep Dive into Linux File Metadata and Management
This article explains the concept of inodes in Unix/Linux file systems, detailing their role in storing file metadata, how to view inode information with commands like stat and df, and the differences between hard links, soft links, and directory entries.
1. What is an inode?
In Linux, a file is stored on disk in units called sectors (512 bytes each) which are grouped into blocks (commonly 4 KB). While file data resides in these blocks, the file's metadata—owner, timestamps, permissions, and block locations—is kept in a separate structure called an inode (index node).
2. Contents of an inode
An inode stores the following information:
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 (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 details with the stat command:
stat example.txt3. Size and layout of inodes
During disk formatting, the OS creates two regions: a data area for file contents and an inode table for metadata. 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).
You can check inode usage with:
df -iTo see the inode size on a device:
sudo dumpe2fs -h /dev/hda | grep "Inode size"4. Inode numbers
Each inode is identified by a unique number; the OS uses this number to locate the file, not the filename. The typical workflow when opening a file is:
Resolve the filename to its inode number.
Read the inode to obtain metadata and block locations.
Read the data blocks to retrieve the file contents.
You can display a file's inode number with:
ls -i example.txt5. Directory files
In Unix/Linux, a directory is itself a file containing a list of directory entries (dirents). Each entry stores a filename and the corresponding inode number. Listing a directory shows only names, while ls -i shows both names and inode numbers, and ls -l displays detailed metadata retrieved via the inode.
ls /etcls -i /etcls -l /etc6. Hard links
Multiple filenames can point to the same inode, creating a hard link. Changes to the file affect all linked names, and deleting one name merely decrements the inode's link count. When the count reaches zero, the inode and its data blocks are reclaimed.
Create a hard link with:
ln source_file target_file7. Soft (symbolic) links
A symbolic link is a special file whose contents are the path to another file. Accessing the symlink causes the OS to follow the stored path to the target. Deleting the target leaves the symlink dangling, producing a “No such file or directory” error. Unlike hard links, a symlink does not increase the target inode's link count.
Create a symbolic link with:
ln -s source_path target_pathSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
