Bird
0
0

You have thousands of files in nested folders. You want to find all .log files modified in the last 7 days and delete them safely. Which command sequence saves time and avoids mistakes?

hard📝 Application Q8 of 15
Linux CLI - Searching and Finding
You have thousands of files in nested folders. You want to find all .log files modified in the last 7 days and delete them safely. Which command sequence saves time and avoids mistakes?
Als /path/*.log | xargs rm
Bfind /path -name '*.log' -mtime +7 -delete
Cfind /path -name '*.log' -mtime -7 -exec rm -i {} \;
Drm /path/*.log
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct find options

    -name '*.log' finds log files; -mtime -7 finds files modified within last 7 days.
  2. Step 2: Use safe delete with confirmation

    -exec rm -i {} \; deletes interactively, avoiding accidental removal.
  3. Final Answer:

    find /path -name '*.log' -mtime -7 -exec rm -i {} \; -> Option C
  4. Quick Check:

    Safe, filtered delete with find = B [OK]
Quick Trick: Use -exec rm -i for safe deletes with find [OK]
Common Mistakes:
  • Using ls with xargs unsafely
  • Wrong mtime sign (+7 vs -7)
  • Deleting without confirmation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes