Bird
0
0

Identify the error in this script snippet for cleaning logs:

medium📝 Debug Q6 of 15
Raspberry Pi - Data Logging and Databases
Identify the error in this script snippet for cleaning logs:
log_dir="/var/log"
find $log_dir -type f -mtime +30 -delete
AUsing -delete is invalid in find command
BMissing quotes around $log_dir may cause errors with spaces
CThe -mtime +30 should be -mtime -30
DThe command deletes directories instead of files
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage in find command

    Without quotes, if $log_dir contains spaces, find may fail or behave unexpectedly.
  2. Step 2: Confirm correct usage of -delete and -mtime

    -delete is valid; -mtime +30 correctly selects files older than 30 days.
  3. Final Answer:

    Missing quotes around $log_dir may cause errors with spaces -> Option B
  4. Quick Check:

    Quote variables to avoid path errors [OK]
Quick Trick: Always quote variables in commands to handle spaces [OK]
Common Mistakes:
MISTAKES
  • Thinking -delete is invalid
  • Confusing +30 with -30 for file age
  • Assuming directories are deleted

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes