cancel
Showing results for 
Search instead for 
Did you mean: 
jeesshnasree
Starfighter Starfighter
Starfighter
  • 3,483 Views

How to purge more than X days logs in Linux

Jump to solution

Hello Team,

 

I am aware logs removal with find command with removal specific days.

below command removal of name_of_log older than 90 days .

find . -type f -name "name_of_log" -mtime +90 -exec rm {} \:

What is the command purge  of name_of_log older than 90 days in Linux.

 

could you please share the command for purge command.

 

similarly , please share name of the logs nullify more than 90 days .

 

I am waiting for your valuable reply.

 

regards,

jeesshansree

0 Kudos
1 Solution

Accepted Solutions
ricardodacosta
Moderator
Moderator
  • 3,479 Views

You could use:

find /var/log/ -mtime +DAYS -delete 

Which I wouldn't recommend because you will be deleting those files without validating them.

To see what those files are first you can use:

find /var/log/ -mtime +DAYS -ls

But a better framework to use is logrotate which is not a daemon, but a binary called by /etc/cron.daily/logrotate.

That binary uses rotation (including retention, and purging) rules defined in /etc/logrotate.conf and /etc/logrotate.d/

 

View solution in original post

2 Replies
ricardodacosta
Moderator
Moderator
  • 3,480 Views

You could use:

find /var/log/ -mtime +DAYS -delete 

Which I wouldn't recommend because you will be deleting those files without validating them.

To see what those files are first you can use:

find /var/log/ -mtime +DAYS -ls

But a better framework to use is logrotate which is not a daemon, but a binary called by /etc/cron.daily/logrotate.

That binary uses rotation (including retention, and purging) rules defined in /etc/logrotate.conf and /etc/logrotate.d/

 

jeesshnasree
Starfighter Starfighter
Starfighter
  • 3,472 Views

Hello @ricardodacosta ,

 

thank you for share the command and detailed description.

 

regards,

jeesshnasree

0 Kudos
Join the discussion
You must log in to join this conversation.