Fundamentals 7 min read

Master Linux Hard and Soft Links: A Complete Step‑by‑Step Guide

This tutorial explains Linux file metadata, the role of inodes, and how hard links and symbolic (soft) links work, providing clear command‑line examples that show creation, modification, deletion, and the distinct behaviors of each link type.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Hard and Soft Links: A Complete Step‑by‑Step Guide

In Linux, each file consists of user data (the actual content) and metadata (attributes such as size, timestamps, owner, and the inode number that uniquely identifies the file on disk).

The inode is the true identifier; the filename is merely a human‑readable label. Links are filesystem objects that point to existing files. There are two main types: hard links and symbolic (soft) links.

Hard link : created with ln myfile hard. Both myfile and hard share the same inode, so they refer to the same data blocks. Modifying either file updates the shared content, as demonstrated by appending a line to hard and seeing the change in myfile.

Symbolic link : created with ln -s myfile soft. The link has its own inode and stores the absolute path to the target file. Deleting the original file leaves the symlink dangling; attempting to read it yields “No such file or directory”. Writing to the symlink recreates the target file because the kernel resolves the stored path.

$ touch myfile && echo "This is a plain text file." > myfile
$ cat myfile
This is a plain text file.
$ ln myfile hard
$ ls -li
25869085 -rw-r--r-- 2 user staff 27 ... hard
25869085 -rw-r--r-- 2 user staff 27 ... myfile
$ echo "New line" >> hard
$ cat myfile
This is a plain text file.
New line
$ ln -s myfile soft
$ ls -li
25869085 -rw-r--r-- 2 user staff 36 ... myfile
25869216 lrwxr-xr-x 1 user staff 6 ... soft -> myfile
$ rm myfile
$ cat hard
This is a plain text file.
New line
$ cat soft
cat: soft: No such file or directory
$ echo "Something" >> soft
$ ls
hard  myfile  soft

In summary, hard links are indistinguishable from the original file because they share the same inode and data blocks, while symbolic links are separate files that store a path reference; they break when the target is removed but can recreate the target when written to.

Linux command reference: https://www.linuxcool.com/
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.

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