Skip to main content

All is File - Test 2

5.4 Special Files and Directories

Understanding /tmp and link

Practice Exam Questions 2

1. Carol has created a hard link named "link1" to a file named "file1.txt" in her current directory. She then modifies the contents of "link1" using a text editor. What will be the result of this action?
 
a) Only "link1" will be modified.
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: 

--------------------------

/* --------------------- */

Explanation:
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:
a) Only "link1" will be modified: Modifying the hard link will also modify the original file.
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.

2. John wants to create a symbolic link to a directory named "docs" located in his home directory. Which command should he use?
a) ln -s ~/docs symlink
b) ln -h docs symlink
c) ln -d docs symlink
d) ln -r ~/docs symlink
/* --------------------- */

--------------------------

Answer 2 Below: 

--------------------------

/* --------------------- */

Explanation:
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.


Explanation of incorrect answers:
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.
 
Correct answer 2: a) ln -s ~/docs symlink

3. Sarah wants to delete a hard link named "link2" to a file named "file2.txt" without affecting the original file. Which command should she use?
a) rm link2
b) rm -f link2
c) rm file2.txt
d) rm -i file2.txt
/* --------------------- */

--------------------------

Answer 3 Below: 

--------------------------

/* --------------------- */

Explanation:
To delete a hard link without affecting the original file, the "rm" command can be used with the name of the hard link to be removed. In this case, Sarah should use the command "rm link2" to delete the hard link "link2" while leaving the original file "file2.txt" intact.

Explanation of incorrect answers:
b) rm -f link2: The "-f" option is used to force the removal of a file or link without prompting for confirmation, but it does not specifically preserve the original file.
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.
 
Correct answer 3: a) rm link2

4. Mark has created a symbolic link named "link3" to a file named "file3.txt" in his current directory. He then moves the symbolic link to another directory using the "mv" command. What will be the result of this action?
a) "link3" will still point to "file3.txt" in the new directory.
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: 

--------------------------

/* --------------------- */

Explanation:
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.


Explanation of incorrect answers:
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.

Correct answer 4: a) "link3" will still point to "file3.txt" in the new directory.
 
5. Jane wants to create a symbolic link to a file named "file4.txt" located in another directory. Which command should she use?
a) ln -s file4.txt symlink
b) ln -r file4.txt symlink
c) ln -s /path/to/file4.txt symlink
d) ln -h file4.txt symlink
/* --------------------- */

--------------------------

Answer 5 Below: 

--------------------------

/* --------------------- */

Explanation:
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:
a) ln -s file4.txt symlink: This command assumes that the target file "file4.txt" is in the current directory, which may not be the case.
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.
 
Correct answer 5: c) ln -s /path/to/file4.txt symlink

6. Alex wants to check the inode number and link count of a symbolic link named "link5". Which command should he use?
a) ls -l link5
b) ls -i link5
c) ls -li link5
d) ls -a link5
/* --------------------- */

--------------------------

Answer 6 Below: 

--------------------------

/* --------------------- */

Explanation:
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:
a) ls -l link5: This command would display the long format listing but not the inode number.
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.

Correct answer 6: c) ls -li link5
 
7. Kevin wants to create a hard link named "link6" to a file named "file6.txt" located in another filesystem. What will happen if he attempts to create the hard link?
a) The hard link will be created successfully.
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: 

--------------------------

/* --------------------- */

Explanation:
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:
a) The hard link will be created successfully: Hard links cannot be created across different filesystems.
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.
 
Correct answer 7: b) Hard links cannot be created across different filesystems.
 
8. John creates a symbolic link named "link1" to a file named "file1.txt" in his current directory. He then moves the file "file1.txt" to a different directory. What will be the result of this action?
a) "link1" will still point to "file1.txt" in the new directory.
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:
Symbolic links in Linux are based on the path of the target file. If the target file is moved to a different directory, the symbolic link will still point to the original path and will be broken.

Explanation of incorrect answers:
a) "link1" will still point to "file1.txt" in the new directory: Symbolic links do not automatically update their target path when the file is moved.
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".
 
9. Alice wants to create a symbolic link named "link2" to a directory named "dir2" located in another directory. Which command should she use?
a) ln -s dir2 link2
b) ln -s /path/to/dir2 link2
c) ln -r dir2 link2
d) ln -d dir2 link2
/* --------------------- */

--------------------------

Answer 9 Below: 

--------------------------

/* --------------------- */

Explanation:
To create a symbolic link to a directory located in another directory, the full path to the target directory must be specified. In this case, Alice should use the command "ln -s /path/to/dir2 link2" where "/path/to/dir2" represents the actual path to the target directory and "link2" is the name of the symbolic link to be created.

Explanation of incorrect answers:
a) ln -s dir2 link2: This command assumes that the target directory "dir2" is in the current directory, which may not be the case.
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.
 
Correct answer 9: b) ln -s /path/to/dir2 link2

10. Sarah wants to remove a symbolic link named "link3" without deleting the target file it points to. Which command should she use?
a) rm link3
b) rm -f link3
c) unlink link3
d) unlink -i link3
/* --------------------- */

--------------------------

Answer 10 Below: 

--------------------------

/* --------------------- */

Explanation:
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:
a) rm link3: This command will delete both the symbolic link and the target file.
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
 
11. Michael creates a symbolic link named "link4" to a file named "file4.txt". He then deletes the original file "file4.txt". What will happen to the symbolic link?
a) The symbolic link will be deleted automatically.
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: 

--------------------------

/* --------------------- */

Explanation:
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.


Explanation of incorrect answers:
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.
 
Correct answer 11: b) The symbolic link will become invalid.

12. Emma creates a symbolic link named "link5" to a file named "file5.txt". She then renames the symbolic link to "newlink". What will happen to the link and the target file?
a) The link will be renamed to "newlink", but the target file remains unchanged.
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: 

--------------------------

/* --------------------- */

Explanation:
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:
b) The link and the target file will be renamed to "newlink.txt": Renaming a symbolic link does not affect the name of the target file.
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.

Correct answer 12: a) The link will be renamed to "newlink", but the target file remains unchanged.
 
13. James creates a symbolic link named "link6" to a directory named "dir6". He then moves the symbolic link to a different directory. What will happen to the link and its functionality?
a) The link will still point to the original directory.
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: 

--------------------------

/* --------------------- */

Explanation:
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.

 
Correct answer 13: b) The link will be updated to point to the new directory.
 
14. Rachel creates a symbolic link named "link7" to a file named "file7.txt" in her current directory. She then displays the information of the symbolic link using the "ls -lh" command. What will be displayed in the output?
a) The permissions and information of "link7" only.
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: 

--------------------------

/* --------------------- */

Explanation:
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:
a) The permissions and information of "link7" only: The output of "ls -lh" includes information about both the symbolic link and the target file.
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. 
 
Correct answer 14: c) The permissions and information of both "link7" and "file7.txt".