Interview Q&A / Linux & Shell

IntermediateIn-depth3 min readUpdated 2 Oct 2026

What is the difference between a hard link and a soft link in Linux?

SHORT ANSWER

A hard link is another name for the same file on disk (the same inode), so the data stays as long as any name exists. A soft (symbolic) link is a small separate file that stores a path to the target; it breaks if the target is moved or deleted, but it can point to directories and across file systems.

Explain it simply

Think of a person who is called "Rahul" at home and "R. Sharma" in the college register. Both names refer to the same person. If the register entry is removed, Rahul still exists. That is a hard link: two names, one actual file.

Now think of a note on the notice board saying "For doubts, go to Room 204". The note is not the teacher; it only tells you where to look. If the teacher moves to another room, the note now sends you to an empty room. That is a soft link (symlink): a pointer to a path, which can go stale.

Example

bash
echo "hello" > original.txt
ln original.txt hard.txt        # hard link
ln -s original.txt soft.txt     # soft (symbolic) link
ls -li
text
1311 -rw-r--r-- 2 ravi ravi  6 Oct  2 11:00 hard.txt
1311 -rw-r--r-- 2 ravi ravi  6 Oct  2 11:00 original.txt
1318 lrwxrwxrwx 1 ravi ravi 12 Oct  2 11:00 soft.txt -> original.txt

Notice three things. hard.txt and original.txt share inode number 1311 and both show a link count of 2. soft.txt has its own inode, starts with l, and its size (12) is just the length of the text "original.txt".

Now delete the original:

bash
rm original.txt
cat hard.txt     # still prints: hello
cat soft.txt     # error: No such file or directory

How it works

In Linux, a file's data and details (size, owner, permissions, where the blocks are) live in an inode. A directory is just a table mapping names to inode numbers. A hard link is one more row in that table pointing to the same inode, and the inode keeps a link count. The data is freed only when the link count reaches zero and no process has the file open.

A symbolic link is its own small file whose content is a path. When you open it, the kernel reads that path and follows it. Because it stores a path and not an inode, it can cross file systems and point to directories, but it also has no idea if the target disappears.

Hard linkSoft link
Same inode as targetYesNo
Works after target is deletedYesNo (dangling)
Can link to directoriesNo (normally)Yes
Can cross file systems or partitionsNoYes
Commandln target nameln -s target name

Real-world use

  • Symlinks switch versions without changing config: /usr/bin/python3 -> python3.12, or a current -> releases/2026-10-02 link for zero-downtime deploys.
  • Nginx on Debian/Ubuntu enables sites by symlinking files from sites-available into sites-enabled.
  • Backup tools like rsync --link-dest use hard links so unchanged files take no extra space across daily snapshots.

Common mistakes

  • Creating a symlink with a relative path from the wrong folder. ln -s target name stores the text you give it, and it is resolved relative to the link's own location, not your current directory.
  • Thinking deleting a hard link frees space. It only removes one name; the space is freed when the last name goes.
  • Thinking a symlink has its own permissions. The rwxrwxrwx shown is ignored; the target's permissions apply.

What to say in the interview

"A hard link is an additional directory entry pointing to the same inode, so both names are equally the file and the data survives until the link count drops to zero. Hard links cannot span file systems or point to directories. A soft link is a separate file containing a path to the target. It can cross file systems and point to directories, but if the target is deleted or moved the link becomes dangling. I create them with ln and ln -s, and ls -li shows the inode numbers to tell them apart."

Follow-up questions

  • What is an inode, and what does it not store? (Hint: the file name.)
  • Why are hard links to directories not allowed?
  • How do you find all broken symlinks in a folder?
  • What happens if you delete a file that a running process still has open?

#linux#filesystem#links#inode

Related questions

Practise more Linux & Shell questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Linux & Shell quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.