XK0-005 · Question #727
A Linux administrator is creating a directory called CompTIA_doc and needs to switch to another location to perform some system-related tasks. Which of the following commands should the…
The correct answer is D. mkdir CompTIA_doc && cd CompTIA_doc. The && operator executes the second command only if the first command succeeds (exits with code 0). So mkdir CompTIA_doc && cd CompTIA_doc creates the directory, and only if that succeeds, changes into it. Option A uses & which runs the first command in the background before…
Question
A Linux administrator is creating a directory called CompTIA_doc and needs to switch to another location to perform some system-related tasks. Which of the following commands should the administrator use for this task?
Options
- Amkdir CompTIA doc & cd CompTIA doc
- Bmkdir CompTIA_doc > cd CompTIA_doc
- Cmkdir CompTIA_doc || cd CompTIA_doc
- Dmkdir CompTIA_doc && cd CompTIA_doc
How the community answered
(55 responses)- B4% (2)
- C5% (3)
- D91% (50)
Explanation
The && operator executes the second command only if the first command succeeds (exits with code 0). So mkdir CompTIA_doc && cd CompTIA_doc creates the directory, and only if that succeeds, changes into it. Option A uses & which runs the first command in the background before the directory exists, causing cd to fail; it also has unquoted spaces in the names. Option B uses > which is a file redirect operator - it would redirect mkdir's output, not chain commands. Option C uses || which is the OR operator - it runs the second command only if the first one FAILS, meaning cd would only execute if mkdir failed.
Topics
Community Discussion
No community discussion yet for this question.