> ## Content Index
> Fetch the complete content index at: https://www.bagz.fr/llms.txt
> Use this file to discover other available public pages before exploring further.

# Apache Tomcat - Get logs directly cleaned with rotation
- URL: https://www.bagz.fr/apache-tomcat-get-logs-directly-cleaned-with-rotation/
- Published: 2016-10-19T15:57:12.000Z
- Updated: 2016-10-19T15:57:12.000Z
- Author: bgazui
- Tags: Linux, #Migrated-1790668826633, #wp, #wp-post, #Import 2026-09-29 08:00

Tomcat allows you to rotate easily your log files with [AccessLogValve](https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access%5FLog%5FValve) but it can be more difficult to get cleaning in logs directories automatically.

For that, you can easily use some smart **find** commands combined with actions:

1. Get logs older than 3 days compressed so they can be smaller but still accessiblefind /var/log/tomcat/ -mtime +3 -regex ".\*\\.\\(log\\|txt\\)$" -exec gzip "{}" \\;
2. Get logs older than 60 days deleted permanentlyfind /var/log/tomcat/ -mtime +60 -name "\*.gz" -exec rm "{}" \\;

You will probably have to adjust the logs path depending on your needs, and you can also modify the retention time for each action. Once the command looks correct with what you're expecting, you can set them up as cron so it can be executed automatically every day.