Difficulty: Easy
Correct Answer: rmdir
Explanation:
Introduction / Context:
Deleting directories is a routine task. Unix/Linux distinguishes between removing empty directories safely and recursively deleting directory trees. Knowing the correct command for empty directories prevents accidental data loss and aligns with least-destructive defaults.
Given Data / Assumptions:
Concept / Approach:
Use 'rmdir dir_name' to remove an empty directory. If the directory is not empty, 'rmdir' will refuse and report an error, prompting you to verify contents with 'ls -A'. For removing non-empty directories, the more dangerous 'rm -r dir_name' is required, often paired with '-i' for safety or used cautiously.
Step-by-Step Solution:
Verification / Alternative check:
Attempting 'rmdir' on a directory with files should fail, protecting you from accidental recursive deletions. Use 'find target_dir -maxdepth 1 -type f' to verify emptiness before removal.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing 'rmdir' with 'rm -r', forgetting hidden files may prevent 'rmdir', and lacking permissions to remove the directory.
Final Answer:
rmdir
Discussion & Comments