Which command is used to remove a directory and all its contents?

Prepare for the LPIC-2 Certification Test with our study tools, including flashcards and multiple choice questions with hints and explanations. Get ready to pass your exam!

The command that is used to remove a directory and all its contents is "rm -r directory_name". This command employs the "rm" (remove) utility with the "-r" option, which stands for "recursive". The recursive option allows the command to navigate through the directory structure and delete all files and subdirectories within the specified directory, ensuring the entire contents are removed.

In contrast, other options provided do not fulfill the requirement to delete a directory with its contents. The "del" command is typically used in DOS and Windows environments for deleting files, not directories, and does not work in Linux. The "rmdir" command is used for removing empty directories only, and it will return an error if the directory contains any files or subdirectories. Lastly, the command "delete -r directory_name" is not a valid command in Linux, as "delete" is not recognized in the shell. Thus, "rm -r directory_name" is the appropriate command for this action.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy