Difficulty: Medium
Correct Answer: rm -r *
Explanation:
Introduction / Context:
Recursive deletion is a powerful but dangerous operation on UNIX systems. The rm utility can remove directories and their contents when used with the appropriate options. Proper understanding prevents accidental data loss and ensures safe automation in scripts.
Given Data / Assumptions:
Concept / Approach:
rm -r enables recursive removal of directories. When combined with a wildcard like , it targets all non-hidden entries in the current directory, descending into directories to remove their contents as well. Add -i to prompt before each removal or -f to force without prompts based on safety needs.
Step-by-Step Solution:
Verification / Alternative check:
Test on a disposable directory structure created with mkdir -p and touch to confirm behavior. Use tree or find to verify no remnants remain.
Why Other Options Are Wrong:
a: rm * removes only files (and empty directories in some shells with special options) in the current directory, not recursive subdirectories.
c: rm all is not a standard command.
d: rm . is DOS-style and misses names without dots; still not recursive.
e: Not applicable because rm -r * is correct.
Common Pitfalls:
Running from the wrong directory; forgetting hidden files; omitting quotes when using dangerous patterns in scripts; not using -i for interactive confirmation in sensitive locations.
Final Answer:
rm -r *
Discussion & Comments