Symbolic links and hard links — what they actually are
A shortcut on your desktop and a symlink look similar, but a symlink and a hard link — despite sharing a command — behave completely differently, and mixing them up is how a 'simple copy' quietly breaks the original file.
Beginner
3 min read
A file is really just a name pointing at data
On disk, the actual file content is stored separately from the human-readable
name you see in a directory listing — the filesystem's internal bookkeeping
(an inode) tracks the real data, and one or more names can point to that
same inode. Both kinds of links this lesson covers are built directly on
that fact, just in different ways.
Symbolic links: a pointer to a path
A symbolic link (symlink) is a small special file that just stores the
path to another file or directory — conceptually similar to a desktop
shortcut:
$ ln -s /var/log/nginx/access.log latest-log$ ls -l latest-loglrwxrwxrwx 1 user user 25 Sep 20 10:12 latest-log -> /var/log/nginx/access.log
Opening latest-log transparently opens the real file at that path. But
because a symlink only stores a path, deleting or moving the original file
breaks the symlink — it becomes a "dangling" link pointing at nothing,
which is a real, common source of "file not found" confusion until you
realize the file you're looking at is a broken pointer, not the actual data.
Hard links: another name for the exact same data
A hard link doesn't store a path at all — it's a second name pointing
directly at the same inode as the original file, meaning the same actual
data on disk:
$ ln original.txt hardlink.txt
Both names are now equally "real" — there's no concept of one being the
"original" and the other a "link" once they're created; editing either name
changes the same underlying data, and the file only actually disappears
once every name pointing to that inode has been deleted, not just one.
The practical difference that actually matters
Symbolic link
Hard link
Stores
A path
A direct reference to the same data
Survives the original being deleted?
No — becomes broken
Yes — data persists until every link is gone
Can link across different disks/filesystems?
Yes
No
Can link to a directory?
Yes
No (with rare exceptions)
Symlinks are far more common in everyday use — for versioned config
directories, "latest" pointers, or making a tool available under a
different name — precisely because they're more flexible (directories,
across filesystems) even though they can break if the target moves.
Why this matters day to day
A directory that "looks empty" after moving what you thought was the real
file, or a program that mysteriously still sees old data after you deleted
a file, are both classic symptoms of not knowing which kind of link you were
looking at. Being able to run ls -l and recognize the -> arrow that marks
a symlink — and knowing a hard link won't show any special marker at all,
since it looks like an ordinary file — is the actual, practical skill this
lesson is building toward.