#! /bin/bash #https://blog.csdn.net/qq_36538012/article/details/79708385 d=`date +%F` exec >> /soft/apache-tomcat-9.0.16/$d"_tomcat".log 2>&1 echo "开始执行清除tomcat日志文件" find /soft/apache-tomcat-9.0.16/logs/ -mtime +30 -name "*.txt" -exec rm -rf {} ; find /soft/apache-tomcat-9.0.16/logs/ -mtime +30 -name "*.log" -exec rm -rf {} ; #フォルダー「/log/」を削除する find /log/ -mtime +200 -exec rm -rf {} ; #删除tomcat日志文件直接删除文件 #find /soft/apache-tomcat-9.0.16/logs/ -name '*.log.*' | xargs rm -f #将文件内容清零 #find /soft/apache-tomcat-9.0.16/logs/ -name 'catalina.out' | xargs truncate -s 0 if [ $? -eq 0 ]; then echo "清除日志成功" else echo "清除日志失败" fi