Linux Administration
medium
Pregunta de Linux Administration #019e3987
Enunciado de la Pregunta
Linux Administration
#hard-link
#inode
#link-count
#unlink
#directory-entry
Medio
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?
A
foo and bar would both be removed.
B
foo would be removed while bar would remain accessible.
Correcto
C
foo would be removed. bar would still exist but would be unusable.
D
Both foo and bar would remain accessible.
E
The user is prompted whether bar should be removed, too.
Explicación Oficial / Explicaciones de la Comunidad
A hard link is a directory entry that points to the same inode as the original file. When foo is deleted, only the directory entry for foo is removed; the inode and its data remain as long as at least one hard link (here bar) exists. Therefore, bar remains fully accessible and usable.
How it Works
- In Linux filesystems, each file is represented by an inode that stores metadata and pointers to data blocks.
- A hard link creates an additional directory entry referencing the same inode. The inode has a link count that tracks the number of directory entries pointing to it.
- Deleting a file (using
rmorunlink) removes the directory entry and decrements the link count. The inode and its data are only freed when the link count reaches zero. - In this scenario, after creating the hard link
bar, the inode forfoohas a link count of 2. Deletingfooreduces the count to 1, so the inode and data persist viabar.
Why the Correct Answer is Right
- The statement "foo would be removed while bar would remain accessible" is correct because
barstill references the same inode, which remains intact.
Why the Incorrect Answers are Wrong
- "Both foo and bar would be removed" is incorrect because deleting
fooonly removes one directory entry;barstill exists. - "foo would be removed. bar would still exist but would be unusable" is incorrect because
baris fully functional; hard links do not depend on the original name. - "Both foo and bar would remain accessible" is incorrect because
foois deleted and its directory entry is gone. - "The user is prompted whether bar should be removed, too" is incorrect; no prompt appears because the system does not track hard link relationships beyond the link count.