Fundamentals 6 min read

Understanding Linux File Storage: Inodes, Blocks, and Links Explained

This guide explains how Linux stores files using inodes, data blocks, and directory entries, details file metadata, outlines the creation and deletion processes, and compares hard and soft links with practical command examples and common pitfalls.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Understanding Linux File Storage: Inodes, Blocks, and Links Explained

File storage in Linux

Linux stores a file in three separate places: the inode holds the file's metadata, the block area stores the actual file data, and the directory entry (a special block) maps the file name to its inode number.

Metadata stored in an inode

inode number (unique identifier)

file type

permissions

size

owner and group

UID and GID

three timestamps (access, modify, change)

link count

File creation process

Allocate a free inode number.

Write the file’s metadata into the inode area.

Allocate data blocks of the required size and store the file’s contents.

File deletion process

The core step is to remove the mapping between the directory entry and the inode, so the file name no longer appears in the directory.

Hard and soft links

Both are part of a file’s attributes and provide additional references without duplicating the file’s data.

Hard links

A hard link creates another pathname that points directly to the same inode.

Cannot be created across different file systems (e.g., ext4 to xfs).

Cannot be created for directories except for the special entries . (current directory) and .. (parent directory).

Soft (symbolic) links

A soft link works like a Windows shortcut and stores a path to the target file.

Can cross partitions and file systems.

Can point to directories.

If the link name is omitted, it defaults to the source file’s name.

When using a relative path, the stored path is relative to the link’s location, not the source file.

Creating links in Linux

# Create a hard link
sudo ln file_name new_file_name

# Create a soft link
sudo ln -s file_name new_file_name

Example:

ehigh@ubuntu:~$ sudo ln general.conf general_1.conf
ehigh@ubuntu:~$ sudo ln -s general.conf general_2.conf

Using relative paths correctly

Given the directory layout:

/home/user/
│
├── docs/
│   └── file.txt
│
└── links/

Creating a link with an incorrect relative path:

# Incorrect
ln -s docs/file.txt links/link_to_file

This creates a link that points to links/docs/file.txt, which is wrong.

Correct command: ln -s ../docs/file.txt links/link_to_file Using an absolute path for the source is recommended to avoid such errors.

Link count details

When a file is created, its hard link count starts at 2 because the directory entry . (the file itself) and the parent directory’s entry both reference it. . – refers to the current directory. .. – refers to the parent directory.

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 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.