010-100 · Question #68
Which command will delete the directory foo with all its content?
The correct answer is B. rm -r foo. The rm command with the -r flag recursively removes a directory and all of its contents, which is required when the directory is non-empty.
Question
Which command will delete the directory foo with all its content?
Options
- Armdir -a foo
- Brm -r foo
- Crm -a foo
- Drmdir foo
How the community answered
(34 responses)- A9% (3)
- B71% (24)
- C15% (5)
- D6% (2)
Why each option
The rm command with the -r flag recursively removes a directory and all of its contents, which is required when the directory is non-empty.
rmdir does not support an -a flag; it is only capable of removing empty directories and has no recursive deletion option.
rm -r foo invokes rm with the recursive flag, which descends into the directory foo and deletes all files and subdirectories before removing foo itself. This is the correct and standard approach for deleting a directory tree regardless of whether it contains content.
rm does not have an -a flag; this is an invalid option that will cause rm to report an error.
rmdir foo only succeeds on empty directories; if foo contains any files or subdirectories, the command will fail with a 'Directory not empty' error.
Concept tested: Recursive directory deletion with rm -r
Source: https://man7.org/linux/man-pages/man1/rm.1.html
Topics
Community Discussion
No community discussion yet for this question.