nerdexam
LPI

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.

The Power of the Command Line

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)
  • A
    9% (3)
  • B
    71% (24)
  • C
    15% (5)
  • D
    6% (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.

Armdir -a foo

rmdir does not support an -a flag; it is only capable of removing empty directories and has no recursive deletion option.

Brm -r fooCorrect

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.

Crm -a foo

rm does not have an -a flag; this is an invalid option that will cause rm to report an error.

Drmdir foo

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

#rm command#directory deletion#recursive remove

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice