Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

Sure. Look at the rotate option in the config file.

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.

share|improve this answer
I am aware of find, but the same is it possible through logrotate ? – Supratik Apr 6 '11 at 8:12
Looks to be. Can't say for sure as I have not done it. But from reading the man page, posted above, you can do it. – Porch Apr 6 '11 at 18:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.