#查出根目錄下的文件夾大小
du -h --max-depth=1 /
java
#清空文件,不刪除日誌文件
echo " " > access.log
tomcat
lsof |grep deleted
格式化lsof的輸出
lsof |grep deleted |awk '!a[$(NF-1)]++{print}' |awk 'BEGIN{print"PROCESS PID\tSIZE\tFILE"}{printf "%-8s\t%s\t%.f-MB\t%s\n",$1,$2,$(NF-3)/1024/1024,$(NF-1)}'
格式化輸出以下日誌
[root@sales-01 ~]# lsof |grep deleted |awk '!a[$(NF-1)]++{print}' |awk 'BEGIN{print"PROCESS PID\tSIZE\tFILE"}{printf "%-8s\t%s\t24,$(NF-1)}' PROCESS PID SIZE FILE rsyslogd 9039 64-MB /run/log/journal/ebb37907456b44e6960f0956dad1a041/system@c981b1c29e0f480daff9659211d2135b-000000000065a6 zabbix_ag 38508 0-MB /var/log/zabbix/zabbix_agentd.log-20181111 java 94568 776-MB /opt/tomcat/tomcat7-jxc-pda/logs/catalina.out java 94568 0-MB /opt/tomcat/tomcat7-jxc-pda/logs/localhost.2019-05-23.log java 94568 0-MB /opt/tomcat/tomcat7-jxc-pda/logs/manager.2019-05-20.log java 94568 0-MB /opt/tomcat/tomcat7-jxc-pda/logs/host-manager.2019-05-20.log
find /data/logs -type f -mtime +3 -name "*.log" -exec rm -f {} \;
code