Master Linux Hard, Soft, and Symbolic Links with Practical Commands
This guide explains the concepts of hard, soft, and symbolic links in Unix/Linux, showing step‑by‑step commands to create, inspect, and remove links, compare inode numbers, and understand their behavior and limitations.
In this guide we introduce what file links are in Unix/Linux and how to use them effectively.
Understanding Links
The man ln command displays that ln creates links between files, without distinguishing soft (symbolic) or hard links.
Soft (Symbolic) Links
A soft link creates a new directory entry that points to the target file's pathname; the new file’s inode points to the old file’s inode.
Hard Links
Hard links make the old and new file share the same inode number, so they are indistinguishable at the filesystem level.
Symbolic Links
In many Unix/Linux systems, the terms "symbolic link" and "soft link" are used interchangeably, but the key difference is that a symbolic link has its own inode pointing to the target’s pathname.
Creating Hard Links
Run man ln to view usage.
Without parameters, ln shows a missing operand error.
Create a file (e.g., touch 123.txt) and then link it with ln 123.txt 321.txt.
Verify with ls -l and ls -li to see identical inode numbers.
Delete the source file; the linked file remains because they share the same inode.
Note: Hard links cannot span directories.
Any change to the file content is reflected in all hard‑linked names.
Creating Soft Links
Create a source file src.txt and add content.
Use ln -s src.txt dst.txt to create a symbolic link.
Observe that ls -l shows a different inode and an l permission flag.
Symbolic links can point to directories as well.
Inodes of source and link differ, confirming they are separate entries.
Files created inside a linked directory appear in both the source and target directories.
Removing Links
Soft or symbolic links can be removed with rm <link-name> or unlink <link-name>. Directories that are symbolic links can be removed similarly.
Key Takeaways
Hard links share the same inode; deleting any name does not delete the data until all links are removed.
Soft links have separate inodes and store the path to the target; they break if the target is removed.
Hard links cannot cross filesystem boundaries or link directories, while soft links can.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
