6

My log files are in the format "2011-03-28.log.php". Log files are created every day. I want to keep 5 days log and rest I want to remove it, which means only 5 log files will be kept and rest everything will be deleted.

Is it possible using Linux logrotate ?

Supratik
  • 2,104
  • 10
  • 49
  • 66

1 Answers1

2

Sure. Look at the rotate option in the config file. http://linuxcommand.org/man_pages/logrotate8.html

If you set it to rotate daily, and keep 5 files, then it will only keep the last 5 long files. Also, since your file name changes, look at the wildcard section of the above man page.

You can also do this.

find /pathtologs/* -mtime +5 -exec rm {} \;

This will delete anything with a modification time of longer then 5 days.

Porch
  • 680
  • 5
  • 12