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.
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)- A9% (3)
- B85% (28)
- C3% (1)
- E3% (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.
Deleting foo only removes that specific directory entry; bar independently references the same inode and is not affected.
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.
bar points directly to the valid inode, not through foo, so it remains fully functional after foo's directory entry is removed.
foo's directory entry is explicitly removed by the delete operation, so foo is no longer accessible by that path.
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
Community Discussion
No community discussion yet for this question.