LFCS · Question #866
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. Deleting the original file that has a hard link only removes one directory entry; the data remains accessible through the hard link until all links to the inode are removed.
Question
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
(36 responses)- B92% (33)
- C6% (2)
- D3% (1)
Why each option
Deleting the original file that has a hard link only removes one directory entry; the data remains accessible through the hard link until all links to the inode are removed.
Hard links mean multiple names point to the same data; deleting one name does not remove all other names or the data itself, unless it's the last link.
A hard link creates an additional directory entry pointing to the same inode as the original file. When `foo` is deleted, its directory entry is removed, and the link count on the inode decreases, but the underlying data and the inode persist because `bar` still points to them, making `bar` fully accessible.
`bar` would remain completely usable because it is just another name referencing the identical data blocks and inode as `foo` did.
`foo` is explicitly stated as deleted, meaning its directory entry is removed from the filesystem.
Deleting a file with existing hard links simply decrements the link count on the inode; there is no prompt to remove other links.
Concept tested: Hard link persistence after original file deletion
Source: https://man7.org/linux/man-pages/man7/symlink.7.html
Topics
Community Discussion
No community discussion yet for this question.