‹ All Linux Interview Questions questions

Linux Interview Question 5: Hard vs Symbolic Links

Linux Interview Questions · Test 1 · question 5 of 10

Filesystems & Storageeasy

In a directory on a single ext4 filesystem, you run:

ln report.csv hard.csv, then ln -s report.csv soft.csv, then rm report.csv

What happens when you now run cat hard.csv and cat soft.csv?

Select one answer
Show answer and explanation

Answer:

  • D. cat hard.csv still prints the data, while cat soft.csv fails because the symlink now points to a name that no longer exists

A hard link is simply another directory entry, another name, for the same inode. After ln, report.csv and hard.csv are equal names for one file, and the inode's link count is 2. rm calls unlink(), which removes a name. The file's data is freed only when the last link is gone and no process has it open. Removing report.csv leaves hard.csv, so the data remains.

A symbolic link is a separate small file whose content is a pathname. soft.csv contains the text report.csv, and it is resolved every time it is used. Once that name is removed, the symlink is dangling, and cat soft.csv fails with "No such file or directory".

Option A is wrong because it treats report.csv as the "real" file. For hard links, no name is the original; each one is equal.

Option B is wrong because a symlink does not add to the target's link count. It is its own inode, holding a path.

Option C reverses the two mechanisms: hard links refer to the inode, symlinks refer to a name.

References: unlink(2) - Linux manual page; symlink(7) - Linux manual page

Practice Test 1 ›

Study guides for Linux Interview Questions