Compress Old Log Files on Linux
Most log files located in /var/log are part of the log rotation and will be compressed automatically. However, in many cases various user applications maintain log files outside of /var/log. These logs are not managed by the system and can consume a lot of disk space if not cleaned up on a regular basis. The simple script below will find all old log files in /opt that are larger than 10Mb and have the name of “something.log.something”. This syntax is most commonly used for old log files created by applications during the log rotation process. For example: /opt/application/logs/application.log.0
|
1 2 3 4 5 |
find /opt -type f -mtime -200 -size +10240k -exec ls -als {} \; | sort -rn | grep "log\." | grep -v "\.gz" | awk '{print $NF}' | while read line do echo "Compressing $line" gzip "${line}" done |
-
Sergeant Pickle
-
Thomas A
-
slipknot0129
-
mr flibble
-
Disrae
-
Shay H
