0Pricing
DevOps Bootcamp · Lesson

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 — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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 data

Hard 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.txt

Hard 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/site

Symlink 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/site

Symlinks 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 linked

Removing 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 symlink

When 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.

Frequently asked questions

Is the “Creating Links: Hard Links & Symlinks” lesson free?

Yes — the full text of “Creating Links: Hard Links & Symlinks” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

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; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

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

  1. Viewing File Content (cat, less, head, tail)
  2. Understanding File Permissions (chmod, chown)
  3. Searching for Files (find, grep)
  4. Creating Links: Hard Links & Symlinks
← Back to DevOps Bootcamp