Skip to content

Symbolic Links, Hard Links, and Inodes: A Beginner Guide

Admin
October 19, 2026
10 min read
Beginner
💻 Target OS: Ubuntu 24.04+ / Debian 12+ / RHEL 9+

Before you begin

  • Applies to:Linux systems with ln, ls, cat, mv, and rm.
  • Where to start:Open one terminal as your regular user. Run the exercise in your home directory.
  • What you need:Use the practice file created in the guide. Keep $HOME as written. You do not need sudo.
Guide tools
Guide tools
0/0 Steps (0%)

A symbolic link is a small file that points to another file’s location. You can use it much like a shortcut. If the target moves, the link can stop working.

A hard link gives an existing file another name. Both names refer to the same file contents. Changing those contents through either name changes what you see through the other.

You will create one text file, try both types of link, and see what happens when a name changes or is removed. You only need a Linux terminal and basic familiarity with copying commands. Use a normal user account; none of these steps needs sudo. These examples use Linux versions of ln, ls, cat, mv, and rm.

A symbolic link points to a file path; two hard-link names share the same file contents.

A symbolic link follows a path. Hard-link names share one file.

01

Create Your Practice Folder

Start Here

Create a new folder called links-practice in your home directory and enter it. The && means “run the next command only if the first command succeeds.” Then use pwd to check where you are.

Terminal window
mkdir "$HOME/links-practice" && cd "$HOME/links-practice" && pwd
❯ What you should see
/home/sam/links-practice
02

Create and Read One Text File

Your First File

printf prints text, and > sends that text into a file. The \n starts a new line. Use cat to read the file back. Because this is a new practice folder, original.txt should not already exist.

Terminal window
printf 'Hello from my file.\n' > original.txt
cat original.txt
❯ Expected file contents
Hello from my file.
03
A Shortcut-Like Link

ln creates a link. Adding -s requests a symbolic link. Put the existing file first and the new link name second. The final command lists the link so you can see where it points.

Terminal window
ln -s original.txt shortcut.txt
ls -l shortcut.txt
❯ The important part of the listing
shortcut.txt -> original.txt
04
Follow the Link

Reading shortcut.txt follows the link to the original file. Add a second line to the original, then read through the link again. The link does not hold a separate copy of the text.

Terminal window
cat shortcut.txt
printf 'A second line.\n' >> original.txt
cat shortcut.txt
❯ Expected result from the final cat command
Hello from my file.
A second line.
05
An Expected Error

mv renames the original file to renamed.txt. The link still points to the old name, original.txt. Reading the link now produces an expected error. The last command confirms that your text still exists under its new name.

Terminal window
mv original.txt renamed.txt
cat shortcut.txt
cat renamed.txt
❯ Expected error, followed by the surviving file contents
cat: shortcut.txt: No such file or directory
Hello from my file.
A second line.
06
Fix the Link

Remove the broken link by its exact name, then create it again pointing to renamed.txt. Here rm shortcut.txt removes the link itself. It does not remove the file that the link points to. Read through the repaired link to check the result.

Terminal window
rm shortcut.txt
ln -s renamed.txt shortcut.txt
cat shortcut.txt
❯ Expected file contents
Hello from my file.
A second line.
07

Give the Same File a Second Name

A Hard Link

This time, run ln without -s. It creates a hard link named second-name.txt. Both names now refer to the same file. The -i option asks ls to show each file’s inode number: a number used to identify a file on a filesystem. Both names should show the same number in this practice folder.

Terminal window
ln renamed.txt second-name.txt
ls -i renamed.txt second-name.txt
❯ Example inode numbers; your number will differ
3210 renamed.txt 3210 second-name.txt
08

Change the Contents Through the Second Name

Shared Contents

Add a line through second-name.txt, then read renamed.txt. The new line appears through both names because they share the same file contents. A hard link is useful as another name, but it is not an independent copy.

Terminal window
printf 'Added through the hard link.\n' >> second-name.txt
cat renamed.txt
❯ Expected result when reading renamed.txt
Hello from my file.
A second line.
Added through the hard link.
09
See the Difference

Remove the name renamed.txt. The file remains accessible through its other hard-link name, second-name.txt. The symbolic link breaks again because it points to the removed pathname. This is the main difference the exercise is designed to show.

Terminal window
rm renamed.txt
cat second-name.txt
cat shortcut.txt
❯ Expected contents followed by a broken-link error
Hello from my file.
A second line.
Added through the hard link.
cat: shortcut.txt: No such file or directory
What you learnedSymbolic linkHard link
What it providesA path to followAnother name for the same file
Target filename is renamed or removedCan become brokenOther hard-link names still work
Changes to the shared file contentsVisible when its target resolvesVisible through either name
Independent backup copyNoNo
Optional: why a hard link is not a backup

A hard link shares the live file’s contents and permissions. An unwanted in-place change affects both names. Some editors instead save by replacing a filename with a newly created file; an existing hard link can then continue referring to the earlier file. That application-dependent behavior makes hard links unsuitable as a general backup strategy. Use a backup method that creates a separate, protected recovery copy.

10

Remove Your Practice Files and Folder

Cleanup

The exercise should now have only second-name.txt and the broken link shortcut.txt left. Inspect the folder first. Remove those two exact paths, leave the folder, then use rmdir to remove it. rmdir only removes an empty directory; if anything unexpected remains, stop and inspect it.

Terminal window
ls -la "$HOME/links-practice"
rm "$HOME/links-practice/second-name.txt" "$HOME/links-practice/shortcut.txt"
cd "$HOME" && rmdir links-practice && printf 'Practice folder removed.\n'
❯ Check that the folder has been removed
Practice folder removed.

The success message confirms the empty practice folder was removed. You have now seen a symbolic link follow a path, a hard link share a file, and the different effects of removing a filename.

References: GNU coreutils ln and ls inode numbers. Continue with file permissions or directory layout.

Comments