I am rotating my logs using logrotate in linux. I want to remove my logs older than 7 days. So I tried maxage option in logrotate but it is not working as expected.

Let say I have 6 logs which is created in the order shown below

Date            filename

18th oct    sample.log.2017-10-18
17th oct    sample.log.2017-10-17
16th oct    sample.log.2017-10-16
15th oct    sample.log.2017-10-15
14th oct    sample.log.2017-10-14
13th oct    sample.log.2017-10-13
12th oct    sample.log.2017-10-12

Today(19th oct) no sample log is created so no log is rotated and also sample.log.2017-10-12 needs to be deleted but it is not deleted why?

find logrotate property file below

/var/log/test/*.log {

    dateformat .%Y-%m-%d
    maxage 7

  • 1
    According to the man pages for log rotate, "maxage count - Remove rotated logs older than <count> days. The age is only checked if the logfile is to be rotated." Since there was no rotation, there no check Oct 19, 2017 at 11:47
  • @RamanSailopal. okay. so is there any way we can achieve this without rotation
    – wazza
    Oct 19, 2017 at 12:03
  • Use the find command with -ctime/mtime and -delete Oct 19, 2017 at 12:06
  • @RamanSailopal if i include that in post rotate same will happen right if there is no rotation
    – wazza
    Oct 19, 2017 at 12:13
  • You will need to run the find and delete of another process, maybe off a daily cron job. Oct 19, 2017 at 12:18

1 Answer 1


Your glob pattern is incomplete - it only matches logs that end with .log. The logs you want to delete after 7 days all end .log.[0-9-]*.

  • 1
    The logs are rotated with a date extension rather than with a sequential numerical .1, .2 (etc.) suffix. This is achieved with the dateext option in the shown configuration (together with dateformat which sets the format of the extension). The actual logfile is called sample.log and the list of names that they show are the already rotated logs.
    – Kusalananda
    Feb 8 at 17:39
  • Yes @Kusalananda I see that. The glob pattern I provided is not invalid, I included a wild card which would result in matching all the rotated logs. Feb 13 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .