Operations 7 min read

Master Linux File Linking: Hard & Symbolic Links Explained with Real Examples

This guide walks you through the Linux ln command, detailing its help output, common options, how to create and modify both hard and symbolic links, and provides step‑by‑step examples for creating, updating, and removing links safely.

Raymond Ops
Raymond Ops
Raymond Ops
Master Linux File Linking: Hard & Symbolic Links Explained with Real Examples

Software Help Text

Usage: ln [OPTION]... [-T] TARGET LINK_NAME
   or:  ln [OPTION]... TARGET
   or:  ln [OPTION]... TARGET... DIRECTORY
   or:  ln [OPTION]... -t DIRECTORY TARGET...
In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory.
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
Create hard links by default, symbolic links with --symbolic.
By default, each destination (name of new link) should not already exist.
When creating hard links, each TARGET must exist. Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.
--backup[=CONTROL]    create a backup of each existing target file
-b                    same as --backup but takes no argument
-d, -F, --directory   create a hard link to a directory (super‑user only)
-f, --force           force removal of any existing target file
-i, --interactive     prompt whether to remove destinations
-L, --logical         dereference TARGETs that are symbolic links
-n, --no-dereference  treat LINK_NAME as a normal file if it is a symbolic link to a directory
-P, --physical        make hard links directly to symbolic links
-r, --relative        create symbolic links relative to link location
-s, --symbolic        make symbolic links instead of hard links
-S, --suffix=SUFFIX   override the usual backup suffix
-t, --target-directory=DIRECTORY  specify the DIRECTORY in which to create the links
-T, --no-target-directory  treat LINK_NAME as a normal file always
-v, --verbose         print name of each linked file
--help                display this help and exit
--version             output version information and exit

Common Link Commands

Create Hard and Soft Links

Hard link : Allows a file to have multiple valid path names, useful for protecting important files from accidental deletion. ln [source_file] [link_file] Soft (symbolic) link : Similar to a Windows shortcut; it stores the path to another file.

ln -s [source_file] [link_file]

Examples

Prerequisite

[root@Servera test]# pwd
/var/test
[root@Servera test]# tree
.
├── soft_link
└── testFiles
    └── 1.txt

Hard Link

[root@Servera test]# ln testFiles/1.txt 2.txt
[root@Servera test]# tree
.
├── 2.txt
├── soft_link
└── testFiles
    └── 1.txt

Soft Link

[root@Servera test]# ln -s testFiles/1.txt soft_link/3.txt
[root@Servera test]# tree
.
├── 2.txt
├── soft_link
│   └── 3.txt -> testFiles/1.txt
└── testFiles
    └── 1.txt

Modify Soft Link

[root@Servera test]# ln -snf testFiles/10.txt soft_link/3.txt
[root@Servera test]# tree
.
├── 2.txt
├── soft_link
│   └── 3.txt -> testFiles/10.txt
└── testFiles
    ├── 10.txt
    └── 1.txt

Delete Soft Link

[root@Servera test]# rm soft_link/3.txt
rm: remove symbolic link 'soft_link/3.txt'? yes
[root@Servera test]# tree
.
├── 2.txt
├── soft_link
└── testFiles
    ├── 10.txt
    └── 1.txt
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.

LinuxShellSystem AdministrationHard LinkSymbolic Linkln command
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

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.