How to delete old log files in Ubuntu

How to delete old log files in Ubuntu
Photo by Clément Hélardot / Unsplash

Large traffic means that you will most probably have to clean some old log files from time to time. We often setup a collection of scripts and crontabs to do this but the base of our scripts is always a single line of code.

The line below shows you a list of files in /var/log/celery folder and that has the *.log ending and that matches the criteria was created more than 30 days ago.

find /var/log/celery -name "*.log" -type f -mtime +30 

If you add -delete to the end of the line it deletes the files instead of outputting them as a list

find /var/log/celery -name "*.log" -type f -mtime +30 -delete