nerdexam
CompTIA

LX0-103 · Question #53

After successfully creating a hard link called bar to the ordinary file foo, foo is deleted from the filesystem. Which of the following describes the resulting situation?

The correct answer is B. foo would be removed while bar would remain accessible.. Hard links share the same inode, so deleting one filename only removes that directory entry while other links to the inode remain fully accessible.

Devices, Linux Filesystems, Filesystem Hierarchy Standard

Question

After successfully creating a hard link called bar to the ordinary file foo, foo is deleted from the filesystem. Which of the following describes the resulting situation?

Options

  • Afoo and bar would both be removed.
  • Bfoo would be removed while bar would remain accessible.
  • Cfoo would be removed. bar would still exist but would be unusable.
  • DBoth foo and bar would remain accessible.
  • EThe user is prompted whether bar should be removed, too.

How the community answered

(33 responses)
  • A
    9% (3)
  • B
    85% (28)
  • C
    3% (1)
  • E
    3% (1)

Why each option

Hard links share the same inode, so deleting one filename only removes that directory entry while other links to the inode remain fully accessible.

Afoo and bar would both be removed.

Deleting foo only removes that specific directory entry; bar independently references the same inode and is not affected.

Bfoo would be removed while bar would remain accessible.Correct

When bar is created as a hard link to foo, both names reference the same inode and the inode's link count increments to 2. Deleting foo removes only that directory entry and decrements the link count to 1, but the inode and its data are not freed. bar continues to point to the same inode and remains fully accessible with no loss of data.

Cfoo would be removed. bar would still exist but would be unusable.

bar points directly to the valid inode, not through foo, so it remains fully functional after foo's directory entry is removed.

DBoth foo and bar would remain accessible.

foo's directory entry is explicitly removed by the delete operation, so foo is no longer accessible by that path.

EThe user is prompted whether bar should be removed, too.

Linux does not prompt the user about related hard links when a file is deleted; the unlink operation is performed silently.

Concept tested: Hard link inode reference counting on deletion

Source: https://man7.org/linux/man-pages/man2/unlink.2.html

Topics

#hard links#inodes#file deletion#link count

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice