A junior Linux administrator needs to remove a test directory tree created under the current working directory. The path is tmp/work/output/archive, and each directory in the path is empty. Management wants the command to eliminate all empty parent directories in that path and display a message for every directory successfully deleted. Which single command meets these requirements?
The rmdir utility can delete only empty directories. Using the -p (or --parents) switch causes rmdir to attempt to remove the specified directory and then work up the path, deleting each parent directory that also becomes empty. The -v (or --verbose) switch prints a diagnostic for every directory processed, providing the requested confirmation. Therefore, combining both options in a single command-rmdir -pv tmp/work/output/archive-fulfills the requirement. Running rmdir with only -p would remove the parents but produce no output. The --ignore-fail-on-non-empty option addresses directory-content errors but neither removes parents nor provides verbose output. rm -r is a different tool, recursively deletes regardless of emptiness, and does not list each directory unless additional flags are supplied, so it does not satisfy the stated conditions.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the -p option do in the rmdir command?
Open an interactive chat with Bash
Why is the -v option useful in rmdir?
Open an interactive chat with Bash
How does rmdir differ from the rm command?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access