Fundamentals 10 min read

Mastering Linux Links: Soft, Hard, and Symbolic Link Commands Explained

This guide explains what file links are in Linux, distinguishes soft, hard, and symbolic links, and provides step‑by‑step command‑line examples for creating, inspecting, and removing each type of link, including handling directories and inode behavior.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering Linux Links: Soft, Hard, and Symbolic Link Commands Explained

What Is a Link?

A link creates a reference between files in a Unix/Linux filesystem. The ln command is used to create links, while ln -s creates symbolic (soft) links. The manual page man ln describes the basic usage without differentiating link types.

Soft (Symbolic) Link

A soft link is a special file that points to another file by pathname. The new file’s inode contains the path to the target, so the inode numbers differ. Permissions show an l flag (e.g., lrwxrwxrwx). Deleting the target leaves a broken link.

shashi@linuxtechi ~}$ touch src.txt
shashi@linuxtechi ~}$ cat > src.txt
Hello World
^C
shashi@linuxtechi ~}$ ln -s src.txt dst.txt
shashi@linuxtechi ~}$ ls -l
lrwxrwxrwx 1 root root 7 Feb 6 16:33 dst.txt -> src.txt
-rw-r--r-- 1 root root 12 Feb 6 16:32 src.txt
shashi@linuxtechi ~}$ cat dst.txt
Hello World

Hard Link

A hard link creates an additional directory entry that points to the same inode as the original file. Both files share the same inode number, so changes to one affect the other. Hard links cannot span filesystems or directories.

shashi@linuxtechi ~}$ touch 123.txt
shashi@linuxtechi ~}$ ln 123.txt 321.txt
shashi@linuxtechi ~}$ ls -l
-rw-r--r-- 2 root root 23 Feb 6 15:52 123.txt
-rw-r--r-- 2 root root 23 Feb 6 15:52 321.txt
shashi@linuxtechi ~}$ ls -li
794583 -rw-r--r-- 2 root root 23 Feb 6 15:52 123.txt
794583 -rw-r--r-- 2 root root 23 Feb 6 15:52 321.txt

If the original file is removed, the hard‑linked file remains because the inode still has a reference count.

shashi@linuxtechi ~}$ rm 123.txt
shashi@linuxtechi ~}$ ls -l
-rw-r--r-- 2 root root 23 Feb 6 15:52 321.txt

Hard links cannot be created for directories; attempting to do so yields an error.

shashi@linuxtechi ~}$ mkdir abc
shashi@linuxtechi ~}$ ln abc def
ln: abc: hard link not allowed for directory

Creating Links in Practice

The guide walks through a full workflow: creating a source file, populating it, making a soft link, verifying inode numbers with ls -li, and observing that modifications to the source are reflected in the link.

shashi@linuxtechi ~}$ touch src.txt
shashi@linuxtechi ~}$ echo "Hello World" > src.txt
shashi@linuxtechi ~}$ ln -s src.txt dst.txt
shashi@linuxtechi ~}$ ls -li
794584 lrwxrwxrwx 1 root root 7 Feb 6 16:33 dst.txt -> src.txt
794583 -rw-r--r-- 1 root root 12 Feb 6 16:32 src.txt

Symbolic links can also point to directories, allowing files created in the linked directory to appear in the target directory.

shashi@linuxtechi ~}$ mkdir abc
shashi@linuxtechi ~}$ ln -s abc def
shashi@linuxtechi ~}$ cd abc
shashi@linuxtechi ~}$ touch 123.txt
shashi@linuxtechi ~}$ cd ..
shashi@linuxtechi ~}$ ls -l
drwxr-xr-x 2 root root 4096 Feb 6 16:34 abc
lrwxrwxrwx 1 root root 3 Feb 6 16:34 def -> abc

Removing Links

Soft links are removed with rm or unlink. Removing the link does not affect the target file.

# rm dst.txt
# unlink dst.txt

Directories that are symbolic links are removed the same way.

# rm def
# unlink def
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 systemHard Linksoft linkSymbolic 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.