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.
More questions on this objective
- A user starts a new terminal window in a running graphical desktop session, which launches bash as an interactive shell that is NOT a login shell. Which file in the user's home directory does bash read in that case? machine-checked
- In bash, which history expansion re-runs the entire previous command line? machine-checked
- Which bash command prints the literal five characters $USER instead of the current user name? machine-checked
- You want /opt/bin searched for executables, after all the directories already in PATH, in the current bash session and in every command started from it. Which command does that? machine-checked
- There is a passwd manual page in section 1 (the command) and another in section 5 (the /etc/passwd file format). Which command opens the section 5 page? machine-checked
- Select the TWO true statements about shell variables and the environment in bash. machine-checked