Fundamentals 10 min read

Master Linux File Links: Soft, Hard, and Symbolic Link Techniques

This guide explains Linux file links—including soft, hard, and symbolic links—covers their differences, demonstrates how to create, inspect, and remove them with command‑line tools, and shows practical effects on inodes and file contents.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux File Links: Soft, Hard, and Symbolic Link Techniques

In this guide we explain what links are in Linux and how to use them effectively.

Soft Link

A soft link (symbolic link) creates a new file that points to the original file's inode, allowing separate inode numbers.

Hard Link

A hard link makes a new directory entry that shares the same inode as the original file; both names refer to the same data.

Symbolic Link

In many Unix/Linux systems, symbolic and soft links are treated the same, but they have distinct inode numbers and are indicated by an "l" in permissions.

Creating Hard Link

Use man ln to view the command description. Running ln without arguments shows usage information.

shashi@linuxtechi ~}$ man ln<br/>ln  - make links between files

To create a hard link between two files:

shashi@linuxtechi ~}$ touch 123.txt<br/>shashi@linuxtechi ~}$ ls -l<br/>-rw-r--r-- 1 root root 0 Feb 6 15:51 123.txt

Then link it:

shashi@linuxtechi ~}$ ln 123.txt 321.txt<br/>shashi@linuxtechi ~}$ ls -l<br/>-rw-r--r-- 2 root root 0 Feb 6 15:52 123.txt<br/>-rw-r--r-- 2 root root 0 Feb 6 15:52 321.txt

Check inode numbers with ls -li to see they match.

shashi@linuxtechi ~}$ ls -li<br/>794583 -rw-r--r-- 2 root root 0 Feb 6 15:52 123.txt<br/>794583 -rw-r--r-- 2 root root 0 Feb 6 15:52 321.txt

Deleting the source file does not affect the hard‑linked file.

shashi@linuxtechi ~}$ rm 123.txt<br/>shashi@linuxtechi ~}$ ls -l<br/>-rw-r--r-- 2 root root 0 Feb 6 15:52 321.txt

Hard links cannot be created across directories.

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

Creating Soft Link

Create a source file and then a symbolic link using ln -s:

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

Reading dst.txt shows the same content as src.txt. The inode numbers differ, and the permissions show an "l" indicating a link.

shashi@linuxtechi ~}$ ls -li<br/>794584 lrwxrwxrwx 1 root root 7 Feb 6 16:33 dst.txt -> src.txt<br/>794583 -rw-r--r-- 1 root root 12 Feb 6 16:32 src.txt

Symbolic Links on Directories

You can also link directories:

shashi@linuxtechi ~}$ mkdir abc<br/>shashi@linuxtechi ~}$ ln -s abc def<br/>shashi@linuxtechi ~}$ ls -l<br/>drwxr-xr-x 2 root root 4096 Feb 6 16:34 abc<br/>lrwxrwxrwx 1 root root 3 Feb 6 16:34 def -> abc

Files created inside the source directory appear in the linked directory and vice versa.

shashi@linuxtechi ~}$ cd abc<br/>shashi@linuxtechi ~}$ touch 123.txt<br/>shashi@linuxtechi ~}$ vi 123.txt<br/>Hello<br/>:wq!<br/>shashi@linuxtechi ~}$ cd ..<br/>shashi@linuxtechi ~}$ ls -l<br/>drwxr-xr-x 2 root root 4096 Feb 6 16:36 abc<br/>lrwxrwxrwx 1 root root 3 Feb 6 16:34 def -> abc

Removing Soft/Symbolic Links

Use rm or unlink to delete a symbolic link.

# rm <soft-link-filename>
# unlink <soft-link-filename>

To remove a symbolic link that points to a directory, the same commands apply.

# rm <soft-link-directory>
# unlink <soft-link-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.

Hard Linksoft linkSymbolic LinkFile Links
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.