Soft Links and Hard Links
Asha's latest harvest file sits deep inside ~/garden/seasons/2026/, and she's tired of typing that long path. She wants a short name in her home folder that always leads to it. Linux has two kinds of link for this, and they behave very differently when the original file is moved or deleted.
The rule
A hard link is another name; a soft link is a signpost.
To see why, you need one fact: a file's data and its name are stored separately. The data and its details (size, owner, permissions) live in a record called an inode. A directory entry is just a name that points to an inode.
Hard link: a second name for the same inode.
$ cd ~/garden/seasons/2026
$ ln harvest.csv harvest-hard.csv
$ ls -li harvest.csv harvest-hard.csv
1048601 -rw-r--r-- 2 asha garden 181 Jun 4 harvest.csv
1048601 -rw-r--r-- 2 asha garden 181 Jun 4 harvest-hard.csv- Both names show the same inode number (
1048601), and the link count is 2. - Neither name is the "original". Delete one and the data stays, reachable through the other. The data is only freed when the last name is gone.
- Limits: a hard link can't point to a directory, and it can't cross to a different filesystem (another disk or partition).
Soft (symbolic) link: a tiny separate file that stores a path.
$ ln -s ~/garden/seasons/2026/harvest.csv ~/harvest
$ ls -l ~/harvest
lrwxrwxrwx 1 asha asha 42 Jun 4 harvest -> /home/asha/garden/seasons/2026/harvest.csv- The type letter is
l, and the arrow shows where it points. - It can point to directories and to other filesystems.
- If the target is moved or deleted, the link is left broken (dangling). It still points to a path that no longer exists.
The argument order is the same as cp: target first, then the new link name.
The shortcut
Ask "what should happen if the original disappears?" If the data should survive, use a hard link. If the link should follow a path, even across disks or to a folder, use a soft link. Most day-to-day links are soft.
Set up
In
~/garden/seasons/2026,harvest-hard.csvis a hard link toharvest.csv, and~/harvestis a soft link to the same file.
A sneaky trap: a relative soft link path is worked out from the link's own folder, not from where you were when you made it. Run from ~/garden/seasons/2026, ln -s harvest.csv ~/h creates ~/h pointing to ~/harvest.csv, which probably doesn't exist. When in doubt, give an absolute target.
Drills
Answer fast — trust the rule.
Which command makes a symbolic link called latest that points to harvest.csv?
Two names show the same inode number in ls -li. What are they?
Asha deletes a file that had a soft link pointing to it. What happens to the link?
Which of these can a hard link NOT do?
Remember
- A hard link is another name for the same inode; a soft link is a signpost that stores a path.
- Ask what should happen if the original disappears. Hard links keep the data, soft links break.
- Target first, then link name (
ln -s target name), and use absolute targets when in doubt.
