Hard Link vs Symbolic Link in Linux: Symlinks and Inodes Explained

Linux gives you two ways to make a file accessible under more than one name: hard links and symbolic links (symlinks). They look similar in a directory listing, and both are created with the ln command, but they work in fundamentally different ways. Choosing the wrong one leads to surprises, such as a link that breaks when you move a file, or a “copy” that still takes up space after you delete the original. Understanding what each link actually points to makes the choice obvious.
This guide explains how hard links and symbolic links differ, what an inode is, when each type breaks, and which one to reach for in common situations.
What an Inode Is
To see the difference, you first need to know how Linux stores a file. Every file’s data is tracked by an inode, a structure that holds the metadata (permissions, owner, size, timestamps) and the location of the data on disk. The file name you see is not the file itself; it is a directory entry that points to an inode. The inode, in turn, points to the data.
This separation is the whole story. A hard link is another directory entry pointing at the same inode. A symbolic link is a small file of its own that contains a path to another name.
For these examples, create a temporary working directory with two sample files:
cd "$(mktemp -d)"
printf 'Example text.\n' > document.txt
printf 'Example text.\n' > report.txtWe will use only these sample files in the deletion examples below. Your inode numbers, ownership, and timestamps will differ from the sample output.
You can see inode numbers with ls -i:
ls -i document.txt1572881 document.txtThe number on the left is the inode number. Two names on the same filesystem that share an inode number refer to the same file. Different filesystems can reuse inode numbers. For a closer look at inodes, including what happens when a filesystem runs out of them, see what an inode is in Linux .
Hard Links
A hard link is an additional name for an existing inode. Both names are equal; neither is the “original.” Create one by passing the existing file and the new name to ln with no options:
ln document.txt backup.txtNow list both with ls -li to see what happened:
ls -li document.txt backup.txt1572881 -rw-r--r-- 2 dejan dejan 14 Jan 1 09:00 backup.txt
1572881 -rw-r--r-- 2 dejan dejan 14 Jan 1 09:00 document.txtBoth names share inode 1572881, so they are the same file viewed through two directory entries. The number 2 after the permissions is the link count: the inode now has two names. Writing to the file in place through either name changes the same data, because there is only one set of data.
Some editors save by writing a new file and renaming it over the old one. In that case, the saved name points to a new inode, while the other hard link keeps the old contents. A hard link is not an independent backup, since an in-place edit affects both names.
Because both names are equal, deleting one only removes that directory entry. To demonstrate this, delete the sample document.txt:
rm document.txtAfter this, backup.txt still contains everything, and the link count drops to 1. The space is reclaimed after the last hard link is removed and no process still has the file open.
Hard links have two firm limits that come from how inodes work:
- They cannot cross filesystems. An inode number is only meaningful within one filesystem, so a hard link and its target must live on the same filesystem.
- They cannot link directories. Allowing this would let you create loops in the directory tree, so the kernel refuses it, even for root.
Symbolic Links
A symbolic link, also called a symlink or soft link, is a separate small file that holds the path to another file or directory. It has its own inode, and its contents are simply the target path. Create one by adding the -s option to ln:
ln -s report.txt shortcut.txtList it with ls -li:
ls -li report.txt shortcut.txt1572895 -rw-r--r-- 1 dejan dejan 14 Jan 1 09:00 report.txt
1572902 lrwxrwxrwx 1 dejan dejan 10 Jan 1 09:05 shortcut.txt -> report.txtThe symlink has a different inode (1572902), the type field starts with l for link, and the listing shows where it points with the -> arrow. When you open shortcut.txt, the kernel follows the stored path to report.txt and works with that file.
Because a symlink only stores a path, it is far more flexible than a hard link:
- It can point across filesystems, since it holds a path rather than an inode number.
- It can point to a directory, which is how most “shortcut to a folder” setups work.
The trade-off is that a symlink depends on its target existing. If you remove or rename report.txt, the symlink still points to the old path and becomes a dangling link:
rm report.txt
cat shortcut.txtcat: shortcut.txt: No such file or directoryThe error comes from the missing target, not from the link being removed. You can still see the dangling symlink with ls -l:
ls -l shortcut.txtlrwxrwxrwx 1 dejan dejan 10 Jan 1 09:05 shortcut.txt -> report.txtThe link is still there, but it points to nothing. A symlink stops working when its stored path no longer resolves to the target. A relative target path is resolved from the directory containing the symlink, so moving that directory together with the target can keep the link working. Renaming a file within the same filesystem leaves its other hard links unchanged.
Key Differences
The table below summarizes how the two types compare:
| Property | Hard link | Symbolic link |
|---|---|---|
| Points to | The same inode (the data) | A path to another name |
| Own inode | No, shares the target’s | Yes, separate inode |
| Cross filesystems | No | Yes |
| Link to a directory | No | Yes |
| Survives deleting the target | Yes, data persists | No, becomes a dangling link |
| Survives moving the target | Yes, for a rename within the filesystem | Only if the stored path still resolves |
| Create with | ln target name | ln -s target name |
Which One to Use
Reach for a symbolic link in most everyday cases. Linking to a directory, pointing to a file on another disk, or creating a shortcut whose target may be replaced later all require a symlink, and the visible -> target makes the relationship easy to understand. The current versions of configuration files and the entries under /etc/alternatives are managed with symlinks for exactly these reasons.
Choose a hard link when you want two names that are truly the same file on one filesystem and you want the data to survive even if one name is removed. Backup and snapshot tools use hard links to make multiple directory trees share unchanged files without storing the data twice, which is efficient because the bytes exist only once.
Conclusion
Use symlinks for directories, references across filesystems, and shortcuts, and use hard links when you want two names for the same file on one filesystem. For the commands themselves, see our guides on creating symbolic links with ln and on removing symbolic links .
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page