In the production environment log is the operation and maintenance personnel to understand and analyze the production environment first-hand information, but the content of the log information is quite large, especially in the public cloud environment running business system, the general system disk in 20g-40g, if there is no reasonable log management scheme, it is easy to appear insufficient storage space phenomenon, Summary of the following several simple methods of log processing, as their own practice notes, at the same time with everyone to exchange learning.
1, some of the number of log lines too much, the time period is longer, there is no important value information, we can delete the previous fixed line number of log files;
find/usr/app/-name filename-exec sed-i ' 1,6000000d ' {} \;
2, we can delete some of the log directly, because RM is a more dangerous command, so the general situation will not be used, so there is a compromise is to use MV replacement cut to a directory and then go to the directory to execute the delete command.
Find./-mtime +30-exec rm-f {} \; LOGPATH=/USR/TOMCATS/APACHE-TOMCAT-7.0.68-RXD/LOGS/LOGNAME1=LOCALHOST_ACCESS_LOG.*CD $logpath, Echo $logpath & &find./-mtime +30-exec mv {}/tmp/\; #find./-name *.txt-mtime +30-exec mv {}/tmp/\;cd/tmp/ && rm-f *.log && rm-f *.txtexit 0
Shell Script Practice Purge Log