Creating Links: Hard Links & Symlinks
Reference one file from many places. Learn the difference between hard links and symbolic links, how to create them with ln, and when to use each.
Creating Links: Hard Links & Symlinks is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
What is a Link?
A link lets more than one name point to file data. Linux supports two kinds: hard links and symbolic (soft) links.
Inodes: The Real File
On disk, a file is an inode holding the data and metadata. A filename is just a directory entry pointing to an inode. This is the key to understanding links.
Creating a Hard Link
A hard link is another directory entry pointing to the same inode. Use ln with no flags.
ln original.txt copy.txt
# both names share the same dataHard Link Behavior
Because both names point to one inode, editing through either changes the same data. The file is only deleted when the last link is removed.
rm original.txt # data still reachable via copy.txtHard Link Limits
Hard links cannot cross filesystems and usually cannot link directories. They also cannot point to a file on another disk or partition.
Creating a Symbolic Link
A symlink is a small file that stores a path to another file. Create it with ln -s.
ln -s /var/www/site current
# current -> /var/www/siteSymlink Behavior
A symlink points to a name, not an inode. If the target is deleted or moved, the symlink becomes a broken (dangling) link.
ls -l current
current -> /var/www/siteSymlinks Across Filesystems
Unlike hard links, symlinks can cross filesystems and can point to directories — which is why they are used for things like rotating release folders.
Spotting Links with ls
ls -l shows symlinks with an arrow and an l file type. For hard links, the link count column shows how many names share the inode.
ls -li
12345 -rw-r--r-- 2 user ... # count 2 = hard linkedRemoving Links
Use rm on a symlink to delete the link, not the target. Take care: a trailing slash on a symlink-to-directory can behave unexpectedly.
rm current # removes only the symlinkWhen to Use Which
Use a symlink for shortcuts, cross-filesystem references, and directories (most common). Use a hard link when you need multiple equal names to identical data on the same filesystem.
Quick Check
Test your understanding.
Recap
You learned about links: hard links add a name to the same inode (same filesystem, no directories, data survives until the last link is gone), while symlinks (ln -s) store a path, can cross filesystems and point to directories, but can break.
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “Creating Links: Hard Links & Symlinks” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Creating Links: Hard Links & Symlinks”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
What will I learn in “Creating Links: Hard Links & Symlinks”?
Reference one file from many places. Learn the difference between hard links and symbolic links, how to create them with ln, and when to use each. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
How long does the “Creating Links: Hard Links & Symlinks” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Viewing File Content (cat, less, head, tail)
- Understanding File Permissions (chmod, chown)
- Searching for Files (find, grep)
- Creating Links: Hard Links & Symlinks