5.4 Special Files and Directories
Understanding /tmp and link
Practice Exam Questions 2
b) Only "file1.txt" will be modified.
c) Both "link1" and "file1.txt" will be modified.
d) Modifying a hard link is not allowed.
--------------------------
Answer 1 Below:
--------------------------
/* --------------------- */
When a hard link is created, it points to the same data on disk as the original file. Modifying either the hard link or the original file will affect both, as they are essentially two different names for the same data. Any changes made to one will be reflected in the other.
Explanation of incorrect answers:
b) Only "file1.txt" will be modified: Modifying the original file will also modify the hard link.
d) Modifying a hard link is not allowed: Modifying a hard link is allowed and will result in changes to the original file as well.
Correct answer 1: c) Both "link1" and "file1.txt" will be modified.
b) ln -h docs symlink
c) ln -d docs symlink
d) ln -r ~/docs symlink
--------------------------
Answer 2 Below:
--------------------------
/* --------------------- */
To create a symbolic link to a directory, the "ln" command should be used with the "-s" option. The "~" symbol represents the user's home directory, and "docs" is the name of the target directory. "symlink" is the name of the symbolic link to be created.
b) ln -h docs symlink: The "-h" option is used to follow symbolic links, not to create them.
c) ln -d docs symlink: The "-d" option is used to create a hard link, not a symbolic link.
d) ln -r ~/docs symlink: The "-r" option is used to recursively create symbolic links within a directory, not to create a single symbolic link.
b) rm -f link2
c) rm file2.txt
d) rm -i file2.txt
--------------------------
Answer 3 Below:
--------------------------
/* --------------------- */
Explanation of incorrect answers:
c) rm file2.txt: This command would delete the original file "file2.txt" and any associated hard links.
d) rm -i file2.txt: The "-i" option prompts for confirmation before deleting a file, but it does not specifically preserve the hard link.
b) "link3" will be broken and no longer point to "file3.txt".
c) "file3.txt" will be moved to the new directory along with "link3".
d) Moving a symbolic link is not allowed.
--------------------------
Answer 4 Below:
--------------------------
/* --------------------- */
When a symbolic link is moved to another directory, it still retains its original target. The link will continue to point to the same file, regardless of its location on the filesystem.
b) "link3" will be broken and no longer point to "file3.txt": Moving a symbolic link does not break its association with the target file.
c) "file3.txt" will be moved to the new directory along with "link3": Only the symbolic link itself is moved, not the target file.
d) Moving a symbolic link is not allowed: Moving a symbolic link is allowed and does not affect its association with the target file.
b) ln -r file4.txt symlink
c) ln -s /path/to/file4.txt symlink
d) ln -h file4.txt symlink
--------------------------
Answer 5 Below:
--------------------------
/* --------------------- */
To create a symbolic link to a file located in another directory, the full path to the target file must be specified. In this case, Jane should use the command "ln -s /path/to/file4.txt symlink" where "/path/to/file4.txt" represents the actual path to the target file and "symlink" is the name of the symbolic link to be created.
Explanation of incorrect answers:
b) ln -r file4.txt symlink: The "-r" option is used to recursively create symbolic links within a directory, not to create a single symbolic link.
d) ln -h file4.txt symlink: The "-h" option is used to follow symbolic links, not to create them.
b) ls -i link5
c) ls -li link5
d) ls -a link5
--------------------------
Answer 6 Below:
--------------------------
/* --------------------- */
To check the inode number and link count of a file or symbolic link, the "ls" command can be used with the "-li" options. This command will display the long format listing with the inode number and link count information for the specified file or symbolic link.
Explanation of incorrect answers:
b) ls -i link5: This command would display only the inode number without the link count.
d) ls -a link5: The "-a" option is used to display hidden files as well, but it does not provide inode number or link count information.
b) Hard links cannot be created across different filesystems.
c) The target file "file6.txt" will be copied to the current filesystem.
d) Creating a hard link requires superuser privileges.
--------------------------
Answer 7 Below:
--------------------------
/* --------------------- */
Hard links can only be created within the same filesystem. If the target file "file6.txt" is located in a different filesystem from the current directory, creating a hard link to it will not be possible.
Explanation of incorrect answers:
c) The target file "file6.txt" will be copied to the current filesystem: Creating a hard link does not involve copying the target file.
d) Creating a hard link requires superuser privileges: Creating a hard link does not necessarily require superuser privileges, but it cannot be done across different filesystems.
b) "link1" will be broken and no longer point to "file1.txt".
c) "file1.txt" will be moved to the new directory along with "link1".
d) Moving a file will automatically update the symbolic link.
--------------------------
Answer 8 Below:
--------------------------
/* --------------------- */
Explanation of incorrect answers:
c) "file1.txt" will be moved to the new directory along with "link1": Moving a symbolic link does not affect the target file.
d) Moving a file will automatically update the symbolic link: Symbolic links are not automatically updated when the target file is moved.
Correct answer 8: b) "link1" will be broken and no longer point to "file1.txt".
b) ln -s /path/to/dir2 link2
c) ln -r dir2 link2
d) ln -d dir2 link2
--------------------------
Answer 9 Below:
--------------------------
/* --------------------- */
Explanation of incorrect answers:
c) ln -r dir2 link2: The "-r" option is used to recursively create symbolic links within a directory, not to create a link to a directory.
d) ln -d dir2 link2: The "-d" option is not valid for creating symbolic links.
b) rm -f link3
c) unlink link3
d) unlink -i link3
--------------------------
Answer 10 Below:
--------------------------
/* --------------------- */
The "unlink" command is used to remove a symbolic link without deleting the target file. Sarah should use the command "unlink link3" to remove the symbolic link named "link3" while preserving the target file.
Explanation of incorrect answers:
b) rm -f link3: The "-f" option is used to force the removal of files, but it will also delete the target file of the symbolic link.
d) unlink -i link3: The "-i" option is used to prompt for confirmation before removing each file, but it is not necessary in this case.
Correct answer 10: c) unlink link3
b) The symbolic link will become invalid.
c) The symbolic link will continue to work.
d) The symbolic link will be renamed to "file4.txt.link".
--------------------------
Answer 11 Below:
--------------------------
/* --------------------- */
Symbolic links point to the path of the target file. If the target file is deleted, the symbolic link will still exist but will become invalid as it points to a nonexistent file.
a) The symbolic link will be deleted automatically: The symbolic link will not be deleted automatically when the target file is deleted.
c) The symbolic link will continue to work: The symbolic link will become invalid when the target file is deleted.
d) The symbolic link will be renamed to "file4.txt.link": The symbolic link's name remains unchanged when the target file is deleted.
b) The link and the target file will be renamed to "newlink.txt".
c) The link will be renamed to "newlink", and the target file will be deleted.
d) Renaming a symbolic link is not allowed.
--------------------------
Answer 12 Below:
--------------------------
/* --------------------- */
When a symbolic link is renamed, only the link itself is affected, and the target file remains unchanged. In this case, the symbolic link "link5" will be renamed to "newlink", but the file "file5.txt" will keep its original name.
Explanation of incorrect answers:
c) The link will be renamed to "newlink", and the target file will be deleted: Renaming a symbolic link does not delete the target file.
d) Renaming a symbolic link is not allowed: Renaming symbolic links is a valid operation in Linux.
b) The link will be updated to point to the new directory.
c) The link will be broken and no longer function.
d) Moving a symbolic link is not allowed.
--------------------------
Answer 13 Below:
--------------------------
/* --------------------- */
When a symbolic link is moved to a different directory, its functionality remains intact, and it will point to the new directory location. In this scenario, "link6" will be updated to point to the new directory location.
Explanation of incorrect answers:
a) The link will still point to the original directory: Symbolic links are updated when they are moved to a different directory.
c) The link will be broken and no longer function: Moving a symbolic link does not break its functionality.
d) Moving a symbolic link is not allowed: Moving symbolic links is a valid operation in Linux.
b) The permissions and information of "file7.txt" only.
c) The permissions and information of both "link7" and "file7.txt".
d) The information displayed will depend on the options used with the "ls" command.
--------------------------
Answer 14 Below:
--------------------------
/* --------------------- */
When using the "ls -lh" command, the output will display the permissions and information of both the symbolic link and the target file it points to. In this case, the output will include the permissions and information of "link7" as well as "file7.txt".
Explanation of incorrect answers:
b) The permissions and information of "file7.txt" only: The output of "ls -lh" includes information about both the symbolic link and the target file.
d) The information displayed will depend on the options used with the "ls" command: The "-lh" options specifically display the permissions and information of both the symbolic link and the target file.