HOWTO : Clean up all log archives after a period of time

If I understand fully and correctly, logrotate just compress log files and the number of compressed log files will be growing up after a period of time. It will not delete those outdated compressed log files automatically.

Therefore, I write the following shell script for the captioned purpose which will delete all the files at /var/log and its subdirectories that are existing more than 30 days.

You can change the existing days by altering the value at DAYEXIST.

Step 1 :

nano /home/samiux/cleanup

————- CUT HERE —————–


find $LOGDIR -type f -mtime +$DAYEXIST -exec rm {} \;

exit 0
————- CUT HERE —————–

sudo chmod +x /home/samiux/cleanup

Step 2 :

Perform the task at 0130 hours every day.

sudo crontab -e

30 1 * * * /home/samiux/cleanup 2 >&1

Step 3 :


** Your comment is welcome when my concept is wrong, thanks **


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: