0

I have log files which have the format as catalina.2020-08-06.log

I want to set a cron job which deletes all the above log files that are older than one week

I am using crontab -e to write the cron

Then, written the following cron:

0 11 * * * rm -rf /var/logs/catalina.2020-*

How to update above cron so that it deletes only the files which are older than one week?

meallhour
  • 13,921
  • 21
  • 60
  • 117
  • 2
    Run: `find /var/log/catalina.*.log -mtime +7 -type f`. If this lists the files you want to delete, then use: `0 11 * * * find /var/log/catalina.*.log -mtime +7 -type f -delete` – John1024 Sep 01 '20 at 21:04
  • thanks a lot. this works!! – meallhour Sep 01 '20 at 22:45

0 Answers0