A student wishes to create symbolic links in a computer system running Unix.…
2005
A student wishes to create symbolic links in a computer system running Unix. Three text files named "file 1", "file 2" and "file 3" exist in her current working directory, and the student has read and write permissions for all three files. Assume that file 1 contains information about her hobbies, file 2 contains information about her friends and file 3 contains information about her courses. The student executes the following sequence of commands from her current working directory
ln -s file 1 file 2
ln -s file 2 file 3
Which of the following types of information would be lost from her file system?
(I) Hobbies (II) Friends (III) Courses- A.
(I) and (II) only
- B.
(II) and (III) only
- C.
(II) only
- D.
(I) and (III) only
Attempted by 13 students.
Show answer & explanation
Correct answer: B
Answer: Friends and Courses are lost.
Recall the ln -s syntax: ln -s target linkname (creates a symbolic link named linkname that points to target).
First command: ln -s file 1 file 2 makes "file 2" a symbolic link pointing to "file 1". The original contents of "file 2" (friends) are replaced by the symlink and so are lost.
Second command: ln -s file 2 file 3 makes "file 3" a symbolic link pointing to "file 2". Since "file 2" is already a symlink to "file 1", "file 3" ends up pointing (indirectly) to "file 1". The original contents of "file 3" (courses) are replaced and thus lost.
As a result, the data in "file 2" (friends) and "file 3" (courses) are lost, while the data in "file 1" (hobbies) remains intact.
Note: This explanation assumes the commands succeed in replacing the existing files (for example, if run with an option that allows overwriting). On many Unix systems, ln will fail if the link name already exists unless forced; the question assumes the links are created so the original files are replaced.