Hard Links vs Soft Links in Linux (Explained Simply with Examples)

Table of Contents

Linux allows multiple names to point to the same file — and it does this through something called links.
There are two types of links in Linux: hard links and soft links (also called symbolic links).

Understanding both helps you manage files efficiently, save space, and avoid accidental data loss.


Every file in Linux has two parts:

  • The inode – stores metadata and points to the file’s data blocks on disk
  • The filename – a label (directory entry) that points to that inode

A “link” is simply another name or reference that connects to the same file — either directly to the inode or to the file path.

Hard vs Soft Links Diagram Hard vs Soft Links Diagram — how filenames map to inodes or paths.


A hard link is another real name for the same file (the same inode).
When you create a hard link, Linux doesn’t copy the data — it simply adds a new directory entry that points to the same inode.

Let’s see it in action.


Step 1: Create a File

echo "hello world" > fileA

List it with inode information:

ls -li fileA

Output:

2684 -rw-r--r-- 1 root root 12 Oct 21 fileA
  • The inode number is 2684.
  • The link count is 1 — only one name points to this inode.

ln fileA fileB

Syntax explanation:

ln <existing_file> <new_link_name>
  • ln → the link command
  • fileA → the existing (original) file
  • fileB → the new name that will point to the same inode

Now list both:

ls -li fileA fileB

Output:

2684 -rw-r--r-- 2 root root 12 Oct 21 fileA
2684 -rw-r--r-- 2 root root 12 Oct 21 fileB
  • Both share the same inode number (2684).
  • The link count is now 2.
  • fileA and fileB are equal names for the same underlying file.

Step 3: Edit One — See the Change in Both

echo "another line" >> fileB
cat fileA

Output:

hello world
another line

Both names refer to the same data — change one, and the other updates automatically.


Step 4: Delete One — The File Still Exists

rm fileA
ls -li fileB

Output:

2684 -rw-r--r-- 1 root root 24 Oct 21 fileB

The file still exists! The inode and data remain until all hard links are removed.


A soft link (or symbolic link) is a shortcut that points to another file’s path, not its inode. This makes it more flexible — but also more fragile.

Let’s recreate fileA and make a symbolic link (fileB) that points to it.


Step 1: Recreate the Original File

echo "testing symbolic link" > fileA

ln -s fileA fileB

Syntax explanation:

ln -s <target_file> <link_name>
  • ln → the link command
  • -s → tells Linux to create a symbolic (soft) link instead of a hard one
  • fileA → the target file that the link will point to
  • fileB → the shortcut name that will reference the path to fileA

Now list both:

ls -l

Output:

-rw-r--r-- 1 root root 23 Oct 21 fileA
lrwxrwxrwx 1 root root 5 Oct 21  fileB -> fileA
  • fileA is the real file.
  • fileB is a symbolic link pointing to the path fileA.
  • The arrow (->) shows this path relationship.

cat fileB

Output:

testing symbolic link

Linux follows the link path and reads the content of fileA.


Step 4: Delete the Target (fileA)

rm fileA
cat fileB

Output:

cat: fileB: No such file or directory

The soft link (fileB) still exists, but it’s now broken — it points to a file path that no longer exists. Unlike hard links, symbolic links depend on the path being valid.


Key Differences

Feature Hard Link Soft (Symbolic) Link
Points to The file’s inode The file’s path
Works across drives or partitions No Yes
Works with directories No Yes
Target deleted? Link still works Link breaks (dangling link)
Inode number Same as original Different inode
Command ln fileA fileB ln -s fileA fileB
Windows equivalent NTFS hard link Shortcut (.lnk)

Real-World Use Cases

Hard Links

  • Save disk space (no duplicate files)
  • Keep files safe from accidental deletion
  • Used by package managers and backup systems

Soft Links

  • Used for configuration files and shortcuts
  • Can link across drives or directories
  • Common for /etc/alternatives and /usr/bin shortcuts

Commands Summary

Action Command
Create a hard link ln fileA fileB
Create a soft link ln -s fileA fileB
View inode numbers ls -li
Identify broken soft links find . -xtype l

TL;DR

Hard links are multiple real names pointing to the same file (same inode). Soft links are shortcuts that point to a file’s path.

Hard links give you durability and efficiency inside one filesystem. Soft links give you flexibility across different locations.


Final Thoughts

Both types of links solve different problems. Once you understand inodes and paths, you’ll start to see why Linux gives you both options — hard links for safety and efficiency, and soft links for flexibility and convenience.


Written by

I’m a Linux System Administrator who’s always been curious about how technology works — from systems and infrastructure to the software that powers them. My goal is to keep learning, share what I discover, and help others break into tech with practical, real-world knowledge.

Start the conversation