Difficulty: Easy
Correct Answer: rmdir
Explanation:
Introduction / Context:
Managing directories is a routine UNIX/Linux task. When a directory is no longer needed and is empty, you can remove it with a specific command. Using the proper utility prevents accidental data loss and ensures compatibility across systems.
Given Data / Assumptions:
Concept / Approach:
The rmdir command removes empty directories. If the directory contains files or subdirectories, rmdir will fail. For non-empty directories, use rm -r carefully. Some systems offer convenience flags like rmdir -p to remove parent directories if they become empty, but the fundamental rule remains: rmdir only works on empty directories.
Step-by-Step Solution:
Verification / Alternative check:
If rmdir fails with “Directory not empty,” remove contents first or use rm -r with extreme caution. Confirm permissions with ls -ld on the parent directory since write/execute on the parent affect deletion.
Why Other Options Are Wrong:
rd, remove, rdir: not standard POSIX commands; may exist on other platforms or shells as aliases, but not portable UNIX. None of the above: incorrect because rmdir is correct.
Common Pitfalls:
Attempting to remove non-empty directories with rmdir; lacking write permission on the parent directory; accidentally using rm -r without double-checking contents.
Final Answer:
rmdir
Discussion & Comments