A technician has removed all files from /srv/backups/daily/2020-12-01. They want to delete that directory plus any empty folders above it under /srv/backups/daily, without affecting /srv/backups. Which command accomplishes this?
unlink /srv/backups/daily/2020-12-01
rmdir --parents /srv/backups/daily/2020-12-01
rm -r /srv/backups/daily/2020-12-01
find /srv/backups/daily -type d -empty | xargs rmdir
The --parents option removes the named directory and then attempts to remove each parent. It stops once it reaches a nonempty directory—in this case, /srv/backups. A plain recursive remove of only the target won’t touch parent folders. Piping empty-directory finds to rmdir only deletes directories already empty at invocation, so it won’t remove the now-empty parent. The unlink utility cannot delete directories.
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 --parents option do in the rmdir command?