Bird
0
0

Given a directory docs containing files and subfolders, what will be the output of rm -r docs if docs exists?

medium📝 Command Output Q4 of 15
Linux CLI - File and Directory Operations
Given a directory docs containing files and subfolders, what will be the output of rm -r docs if docs exists?
ADeletes only files inside 'docs' but keeps subdirectories
BShows an error saying 'docs' is a directory
CLists all files inside 'docs' without deleting
DDeletes 'docs' directory and all its contents without any message
Step-by-Step Solution
Solution:
  1. Step 1: Understand behavior of rm -r on directories

    The -r option removes directories and all contents recursively without prompt by default.
  2. Step 2: Apply to 'docs' directory

    Since 'docs' exists, rm -r docs deletes it and all files and subdirectories silently.
  3. Final Answer:

    Deletes 'docs' directory and all its contents without any message -> Option D
  4. Quick Check:

    rm -r deletes directory recursively silently [OK]
Quick Trick: rm -r deletes directories and contents silently by default [OK]
Common Mistakes:
MISTAKES
  • Expecting error on directory removal with -r
  • Thinking subdirectories remain after rm -r
  • Assuming rm -r lists files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes