Article From:

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


chmod +x

crontab -e
*/1 * * * * /usr/local/xiao_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 *