In Linux, a link is a way to reference the same file by more than one name. There are two kinds: hard links and soft links (also called symbolic links or symlinks). They look similar at first, but they behave very differently under the hood.
In this guide, we’ll explain both types with detailed examples and sample output on Ubuntu Linux.
Table of Contents
Understanding inodes
To understand links, you first need to understand the inode. Every file on a Linux filesystem has an inode—a data structure that stores the file’s metadata (permissions, owner, size, timestamps) and, crucially, the location of its data blocks on disk. The file name is just a label that points to an inode.
You can see the inode number of a file with ls -i:
ls -i original.txt
1234567 original.txt
For more, see how to get a file’s inode number in Linux.
What is a hard link?
A hard link is a second name that points to the same inode as the original file. Both names are equal—there is no “original” and “copy.” They share the same data on disk, so a change through one name is visible through the other.
Key traits of hard links:
- They share the same inode number.
- They cannot span different filesystems.
- They normally cannot be created for directories.
- The data survives until all hard links are removed.
Create a hard link
First, create a file:
echo "Hello, Linux" > original.txt
Now create a hard link with ln (no options):
ln original.txt hardlink.txt
Check both with ls -li (the -i shows the inode, -l the details):
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
ls -li original.txt hardlink.txt
1234567 -rw-r--r-- 2 user user 13 Sep 6 10:00 hardlink.txt
1234567 -rw-r--r-- 2 user user 13 Sep 6 10:00 original.txt
Notice two things:
- Both files have the same inode number (
1234567). - The link count is now
2(the number after the permissions), meaning two names point to this inode.
Because they share data, editing one changes the other:
echo "Second line" >> hardlink.txt
cat original.txt
Hello, Linux
Second line
What is a soft link (symbolic link)?
A soft link is a special file that simply stores the path to another file. It has its own inode and its own tiny bit of data—the target’s path. Think of it like a shortcut. If the target is moved or deleted, the symlink is left pointing at nothing (a “broken” or “dangling” link).
Key traits of soft links:
- They have a different inode from the target.
- They can span different filesystems.
- They can point to directories.
- They break if the target is removed or moved.
Create a soft link
Use ln -s (the -s means symbolic):
ln -s original.txt softlink.txt
Check with ls -li:
ls -li original.txt softlink.txt
1234567 -rw-r--r-- 2 user user 13 Sep 6 10:00 original.txt
2345678 lrwxrwxrwx 1 user user 12 Sep 6 10:01 softlink.txt -> original.txt
This time:
- The inode numbers are different (
1234567vs2345678). - The file type is
l(the first character oflrwxrwxrwx), marking it a link. - The
-> original.txtshows where the symlink points.
You can confirm the target with readlink:
readlink softlink.txt
original.txt
What happens when you delete the original
This is where the two types differ most. Let’s remove the original file:
rm original.txt
The hard link still works, because the data lives with the inode, and the inode isn’t freed until its link count reaches zero:
cat hardlink.txt
Hello, Linux
Second line
The soft link is now broken, because its target path no longer exists:
cat softlink.txt
cat: softlink.txt: No such file or directory
A broken symlink is easy to spot with ls -l—many terminals highlight it in red, and it still shows the (now invalid) -> target. For safe cleanup of stray files, see how to delete files in Linux.
Hard link vs soft link: the differences
| Feature | Hard link | Soft link (symlink) |
|---|---|---|
| Inode | Same as original | Its own inode |
| Points to | The file’s data (inode) | The file’s path |
| Across filesystems | No | Yes |
| Link to a directory | No (normally) | Yes |
| If original is deleted | Still works | Breaks (dangling) |
| Created with | ln src link | ln -s src link |
File type in ls -l | - (regular) | l (link) |
When to use each
- Use a hard link when you want two truly equivalent names for the same data on the same filesystem, and you want the data to persist even if one name is removed.
- Use a soft link when you need to link across filesystems, link to a directory, or create a shortcut that clearly points to a known path—for example,
/usr/bin/python -> python3.
Summary
Hard links and soft links both let you reference a file by more than one name, but they work differently:
- A hard link is another name for the same inode and data.
- A soft link is a separate file that stores the path to a target.
Use ls -li to compare inode numbers and link counts, and readlink to see where a symlink points. For a related take, see hard links and symbolic links in Ubuntu Linux, and to review the ls output fields, see understanding the ls command in Linux.



