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.


Which command should you use to delete an empty directory?

  1. rmdir

  2. rmdir -r

  3. rm -r

  4. rm

The correct answer is: rmdir

The command used to delete an empty directory is "rmdir." This command is specifically designed for removing directories and it will only succeed if the directory is empty. If the specified directory contains files or subdirectories, the command will return an error, preventing accidental data loss. Using "rmdir" ensures a safer execution because you can only delete directories that do not contain any files or other directories, avoiding the risk of unintentional deletions in a directory hierarchy. Other commands like "rm" are more versatile and can delete files or directories regardless of their contents when used with certain flags (like the recursive option, -r). However, "rm" does not specifically indicate whether it’s removing a directory or file, which could lead to confusion in managing file systems. Thus, for the task of deleting empty directories specifically, "rmdir" is the most appropriate and clear choice.