You are updating a deployment script that runs with the default umask of 0022. The script must create the entire path /srv/git/repos/clientX/app1 in one shell instruction, even if some or all of the intermediate directories are missing. The final directory (app1) has to end up with the permission bits rwxrwsr-x (octal 2775) so that the gitusers group can write to it and new files inherit that group ID. Intermediate directories should keep their normal 0755 permissions that result from the current umask. Which command meets all of these requirements?
The mkdir command with the -p option creates any missing parent directories and suppresses errors if they already exist. The -m option sets the mode (permissions). When used together, the specified mode is applied only to the final directory named on the command line. Parent directories created with -p receive default permissions based on the current umask (0755 in this scenario). Therefore, mkdir -p -m 2775 /srv/git/repos/clientX/app1 correctly creates the entire path, sets the mode of app1 to 2775 (including the required setgid bit), and leaves the parent directories with the default 0755 permissions.
Attempting to use umask to set permissions before running mkdir -p would not apply the special setgid bit and would result in incorrect permissions.
Running mkdir with -m but without -p would fail if any parent directories in the path do not already exist.
The install -d command also creates parent directories, but it applies the mode specified with -m to every new directory it creates, not just the final one. This would incorrectly change the permissions of the intermediate directories.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the 'umask' command do in Linux?
Open an interactive chat with Bash
What does the 'setgid' bit accomplish for directories?
Open an interactive chat with Bash
How does the '-p' option in 'mkdir' work?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access