nerdexam
CompTIA

XK0-005 · Question #761

A Linux administrator is creating a directory called CompTIA_doc, and it 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 exits successfully (exit code 0). Using 'mkdir CompTIA_doc && cd CompTIA_doc' ensures the directory is created before attempting to change into it - if mkdir fails (e.g., directory already exists with…

System Management

Question

A Linux administrator is creating a directory called CompTIA_doc, and it 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

(58 responses)
  • A
    2% (1)
  • B
    3% (2)
  • D
    95% (55)

Explanation

The '&&' operator executes the second command only if the first command exits successfully (exit code 0). Using 'mkdir CompTIA_doc && cd CompTIA_doc' ensures the directory is created before attempting to change into it - if mkdir fails (e.g., directory already exists with error), cd is never attempted. A single '&' runs the first command in the background and immediately starts the second, which would fail because the directory may not exist yet. '+' is not a valid shell operator. '||' is a logical OR, running the second command only if the first fails - the opposite of the intended behavior.

Topics

#File System Commands#Directory Operations#Command Chaining#Shell Operators

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice