Article From:https://www.cnblogs.com/xxoome/p/9967847.html

1、Commands to delete logs

find Directory path-mtime + days-name"file name" -exec rm -rf {} \;

For example:Find/usr/local/tomcat/logs/ -mtime +7 -name "*.log" -exec rm -rf {} \;

Explain:Find: Linux lookup command, user finds files with specified conditions/usr/local/tomcat/logs/:Target directories to be cleaned up-mtime:Standard sentence writing+10:Number represents days.-name "*.log":Type of target file, all files with log-exec:Fixed writingRM-rf:Force deletion of files including directories{}\;;: Fixed notation, a pair of braces+Space + + +;

2、Creating timed tasks

vim auto-del-log.sh

chmod +x auto-del-log.sh

crontab -e
*/1 * * * * /usr/local/xiao_sh/auto-del-log.sh >/dev/null 2>&1

 

Link of this Article: Linux cleanup log script

Leave a Reply

Your email address will not be published. Required fields are marked *