RHEL Linux - Red Hat System Administration Practice Exam

Disable ads (and more) with a membership for a one time $4.99 payment

Study for the RHEL Linux - Red Hat System Administration Exam. Enhance your knowledge with flashcards and multiple-choice questions, complete with hints and explanations. Prepare for your certification!

Practice this question and more.


What option would you use with the rm command to remove directories and their contents recursively?

  1. -f

  2. -r

  3. -i

  4. -d

The correct answer is: -r

Using the rm command with the -r option is essential for removing directories and their contents recursively. The recursive deletion is particularly important when you want to eliminate a directory that contains files or other subdirectories, as the rm command, by default, only works on files. When the -r flag is applied, it tells the command to delve into the directory and delete all nested files and directories as well. For instance, if you have a directory structure with multiple levels of directories and files, running rm -r on the main directory will ensure that everything within it is deleted. This not only simplifies the process of clearing out entire directory trees but also saves time and effort, as there’s no need to manually specify each item individually. It's also worth noting that while the -f (force) option can suppress warnings and the -i (interactive) option prompts before deletion, these modifiers do not affect the recursive aspect of the operation. The -d option is generally used with rmdir to remove empty directories and does not apply to situations where you need to delete a directory filled with contents.