Which command in UNIX is used to remove an empty directory?

Which command in UNIX is used to remove an empty directory?

a) rmdir
b) rm
c) deldir
d) delete

Answer:

a) rmdir

Explanation:

The rmdir command in UNIX is used to remove an empty directory. If the directory contains any files or subdirectories, the command will not delete it, and an error message will be displayed. The directory must be empty for this command to work.

For example, running rmdir folder_name will delete the folder if it contains no files or subdirectories. If you want to remove a non-empty directory, you will need to use the rm -r command instead, which deletes directories and their contents recursively.

Using rmdir is helpful for simple directory clean-up operations. By understanding the difference between rmdir and rm -r, users can manage directories more effectively and avoid unintentional data loss.

Reference:

Top 50 Unix MCQ Questions & Answers

Scroll to Top