Linux – Delete files with logrotate

linuxlogrotate

Is it possible JUST to delete the log files in a directory by using logrotate w/o actually rotating them? We have an app that generates logs in the following format: app.log.DD_MM_YYYY. I am unsuccessful with logrotate having the following config:

/opt/log/app/app.log.* {
         rotate 0
         missingok
         nomail
}

Can log rotate do this or should I just write a script and place it within cron?

Best,
-Iulian

Best Answer

In that case you may want to use postrotate. In the example below postrotate will delete files that are older that 1 day after logs been rotated, feel free to modify it to fit your needs.

/opt/log/app/app.log.* {
        missingok
        nomail
postrotate
        /usr/bin/find /opt/log/app/ -name "app.log.*" -type f -mtime +0 -exec rm {} \;
endscript
}