All mock tests are FREE till 31 December — register to save your progress

In UNIX, which single command creates the directory "PIS" together with its two subdirectories "progs" and "data" (i.e. PIS/progs and PIS/data), all newly created in one invocation?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: C. mkdir PIS PIS/progs PIS/data

Explanation

Without the -p flag, mkdir processes its arguments left to right and fails on any path whose parent directory does not yet exist. Option (iii), mkdir PIS PIS/progs PIS/data, lists PIS first, so by the time the command reaches PIS/progs and PIS/data their parent PIS has already been created in that same invocation, so all three succeed. Option (i) tries to create PIS/progs and PIS/data before PIS exists and fails; option (ii) creates three unrelated top-level directories (PIS, progs, data) instead of nesting them inside PIS; option (iv) only creates one subdirectory path plus a stray top-level "data". Hence option (iii).

More Software Engineering questions