Bird
0
0

Identify the error in this Raspberry Pi log rotation script snippet:

medium📝 Debug Q14 of 15
Raspberry Pi - Data Logging and Databases
Identify the error in this Raspberry Pi log rotation script snippet:
logfile="/var/log/app.log"
backup="/var/log/app.log-$(date +%Y%m%d)"

mv $logfile $backup
> $logfile
find /var/log -type f -mtime 7 -delete
AThe find command should use -mtime +7 to delete files older than 7 days
BThe mv command syntax is incorrect
CThe > $logfile line should be before mv command
DThe backup filename format is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check the find command usage

    The find command uses -mtime 7 which matches files exactly 7 days old, not older than 7 days.
  2. Step 2: Correct the find command

    To delete files older than 7 days, use -mtime +7 instead of -mtime 7.
  3. Final Answer:

    The find command should use -mtime +7 to delete files older than 7 days -> Option A
  4. Quick Check:

    find -mtime +7 deletes older files [OK]
Quick Trick: Use + before days in -mtime to delete older files [OK]
Common Mistakes:
MISTAKES
  • Using -mtime 7 deletes only files exactly 7 days old
  • Misplacing the > $logfile line
  • Incorrect mv command syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes