5.4 Special Files and Directories
Understanding /tmp and link
Practice Exam Questions 1
Scenario:
1. A developer needs to store temporary files that should persist between reboots. Which directory should the developer choose?b) /var/tmp
c) /run
d) /var/run
--------------------------
Answer 1 Below:
--------------------------
/* --------------------- */
According to the Filesystem Hierarchy Standard (FHS), the /var/tmp directory is intended for storing temporary files that should not be cleared during system boot-up. Files stored in this directory are expected to persist between reboots, making it suitable for temporary data that needs to be retained across system restarts.
Explanation of incorrect answers:
The /tmp directory is recommended for temporary files that do not need to persist between invocations of a program. It is cleared during system boot-up, so files stored here will not survive a reboot.
c) /run:
The /run directory contains run-time variable data used by running processes, but it must be cleared during system boot-up. Files stored here will not persist between reboots.
d) /var/run:
Although /var/run was once used for run-time variable data, on some systems it may be a symbolic link to /run. Like /run, it must be cleared during system boot-up and does not guarantee persistence between reboots.
Scenario:
2. A program needs to create multiple run-time files. Which directory should the program use?b) /var/tmp
c) /run
d) /var/run
--------------------------
Answer 2 Below:
--------------------------
/* --------------------- */
The /run directory contains run-time variable data used by running processes. If a program requires multiple run-time files, it may create subdirectories within the /run directory. However, it is important to note that the contents of the /run directory are cleared during system boot-up.
Explanation of incorrect answers:
The /tmp directory is not specifically intended for run-time variable data. It is cleared during system boot-up and is typically used for temporary files that do not need to persist between invocations of a program.
b) /var/tmp:
The /var/tmp directory is suitable for storing temporary files that should persist between reboots, but it is not specifically designed for run-time variable data.
d) /var/run:
Scenario:
3. A developer wants to store temporary files that will be erased during system boot-up. Which directory should be used?b) /var/tmp
c) /run
d) /var/run
--------------------------
Answer 3 Below:
--------------------------
/* --------------------- */
Explanation:According to the Filesystem Hierarchy Standard (FHS), the /tmp directory is recommended for temporary files that are not expected to persist between invocations of a program. The convention is to clear this directory during system boot-up, although it is not mandatory.
Explanation of incorrect answers:
The /var/tmp directory is intended for storing temporary files that should persist between reboots. It is not cleared during system boot-up.
c) /run:
The /run directory contains run-time variable data and must be cleared during system boot-up. Files stored here will not be erased solely during system boot-up.
d) /var/run: Although /var/run was once used for run-time variable data, on some systems it may be a symbolic link to /run. The contents of this directory are cleared during system boot-up, but it is not specifically designed for temporary files.
Scenario:
4. A program needs to store temporary files but wants to follow the FHS conventions. Which directory should the program choose?b) /var/tmp
c) /run
d) Any location on the system
--------------------------
Answer 4 Below:
--------------------------
/* --------------------- */
The Filesystem Hierarchy Standard (FHS) recommends certain directories for storing temporary files, such as /tmp and /var/tmp. However, it does not restrict a program from creating temporary files elsewhere on the system. While it is good practice to follow FHS conventions, it is not mandatory.
Explanation of incorrect answers:
The /tmp directory is one of the recommended locations for storing temporary files according to FHS. However, it is not the only possible location, and the program can choose a different location if required.
b) /var/tmp:
The /var/tmp directory is another recommended location for storing temporary files. However, it is not the only permissible location, and the program can choose an alternative location if needed.
c) /run:
The /run directory is not specifically designated for storing general temporary files. It is intended for run-time variable data used by running processes, such as process identifier files.
Scenario:
5. A developer wants to store temporary files that will persist between reboots. Which directory should be used?b) /var/tmp
c) /run
d) /var/run
--------------------------
Answer 5 Below:
--------------------------
/* --------------------- */
The /var/tmp directory is intended for storing temporary files that should not be cleared during system boot-up. Files stored in this directory will usually persist between reboots, making it suitable for temporary data that needs to be retained across system restarts.
Explanation of incorrect answers:
The /tmp directory is recommended for temporary files that do not need to persist between invocations of a program. It is cleared during system boot-up, so files stored here will not survive a reboot.
c) /run:
The /run directory contains run-time variable data used by running processes and must be cleared during system boot-up. Files stored here will not persist between reboots.
d) /var/run:
Although /var/run was once used for run-time variable data, on some systems it may be a symbolic link to /run. Like /run, it must be cleared during system boot-up and does not guarantee persistence between reboots.
Scenario:
6. A program needs to create a process identifier file (.pid). Where should the program store this file?b) /var/tmp
c) /run
d) /var/run
--------------------------
Answer 6 Below:
--------------------------
/* --------------------- */
The /run directory contains run-time variable data used by running processes, including process identifier files (.pid). Storing the .pid file in the /run directory follows the recommended practice for managing run-time data.
Explanation of incorrect answers:
The /tmp directory is not specifically designed for storing process identifier files. While it is possible to store the .pid file here, it does not follow the recommended practice for managing run-time data.
b) /var/tmp:
The /var/tmp directory is intended for storing temporary files that should persist between reboots, but it is not specifically designated for process identifier files.
d) /var/run:
Although /var/run was once used for run-time variable data, on some systems it may be a symbolic link to /run. Storing the .pid file in this directory does not guarantee compatibility across different Linux distributions.
Scenario:
7. A program decides to create temporary files in a non-standard location. What should the developer consider?b) The files may not follow the conventions set by the FHS.
c) The files will persist between reboots.
d) The files will be stored in the /var/tmp directory.
--------------------------
Answer 7 Below:
--------------------------
/* --------------------- */
The Filesystem Hierarchy Standard (FHS) defines standard locations for temporary files on Linux systems. While it does not prevent a program from creating temporary files elsewhere, it is good practice to respect the conventions set by the FHS. By choosing a non-standard location, the developer may deviate from established practices.
Explanation of incorrect answers:
Correct answer 7: b) The files may not follow the conventions set by the FHS.
b) Write permission
c) Execute permission
d) Sticky bit
--------------------------
Answer 8 Below:
--------------------------
/* --------------------- */
The sticky bit is a special permission that, when set on a directory, prevents users from removing or renaming a file within that directory unless they own the file. It is commonly used for system-wide temporary directories to maintain file security in a multiuser environment.
Explanation of incorrect answers:
b) s
c) w
d) r
--------------------------
Answer 9 Below:
--------------------------
/* --------------------- */
Explanation:Directories with the sticky bit set display a "t" symbol in place of the "x" permission in the output of "ls -l." This symbol visually represents the presence of the sticky bit and helps identify directories where file deletion or renaming by other users is restricted.
Explanation of incorrect answers:
b) s:
c) w:
d) r:
Correct answer 9: a) t
b) 755
c) 1755
d) 1777
--------------------------
Answer 10 Below:
--------------------------
/* --------------------- */
Explanation of incorrect answers:
b) 755:
This numeric mode represents the permissions rwxr-xr-x, which does not include the sticky bit.
d) 1777:
b) +s
c) +w
d) +r
--------------------------
Answer 11 Below:
--------------------------
/* --------------------- */
Explanation of incorrect answers:
c) +w:
d) +r:
12. How can the sticky bit be disabled for a directory using "chmod"?
a) chmod -t directory
b) chmod +s directory
c) chmod -w directory
d) chmod -r directory
--------------------------
Answer 12 Below:
--------------------------
/* --------------------- */
The sticky bit can be disabled for a directory using the "chmod" command with the "-t" parameter. The minus sign (-) signifies removing the specified permission, and "t" indicates the sticky bit.
Explanation of incorrect answers:
c) chmod -w directory:
d) chmod -r directory: