The path archive/2023/logs is empty, and so are its parents archive/2023 and archive once it is gone. You want all three removed in one command, and the command must stop with an error rather than delete any directory that still has something in it. Which command do you run?

LPIC-1 Exam 101-500, objective 103. GNU and Unix commands medium

Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.

Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

The options

Correct rmdir -p archive/2023/logs

Correct. -p removes the named directory and then each parent component in turn, stopping with an error as soon as one of them is not empty. Nothing with content in it is ever deleted.

Not correct rmdir archive/2023/logs

Wrong in scope. This removes only the final component, logs, and leaves archive/2023 and archive behind.

Not correct rm -r archive

Wrong, and it violates the safety requirement. -r deletes the tree and everything in it, so a directory that unexpectedly still held files would be destroyed without a word.

Not correct rm -d archive/2023/logs

Wrong in scope. rm -d does remove an empty directory, and refuses a non-empty one, but it acts on the named directory only — the parents survive.

Why

rmdir refuses any directory that is not empty, which is what makes it the safe tool when emptiness is the precondition rather than the goal. -p turns one path into a chain of removals from the leaf upwards, and it stops at the first non-empty component. rm -r is the opposite contract: it removes the content too, so it never fails for that reason.

Where this comes from

Cited
manual page rmdir(1)

Practise this

Reading one question is not practice. The trainer will draw a short set from objective 103 and space the ones you get wrong.

Practise LPIC-1 Exam 101-500

More questions on this objective

All questions on GNU and Unix commands

Practise LPIC-1 Exam 101-500