1, the preface

In o&M, programs such as Java scripts always print logs and occupy large disk space, so logs need to be cleared periodically. The basic principle is to use crontab to make scripts such as Java scripts run at 10:00 PM every day to clear logs generated 30 days ago.

2, code,

#! /bin/bash
 
Delete. TXT files from tomcat/logs 30 days ago :wq! I thing
find /home/a/tomcat/logs -mtime +30 -name "logs.*" -exec rm -rf {} \;
 
#tomcat/logs: Prepare the directory to be cleaned;
#-mtime: +30: find files 30 days ago;
#"logs." finds all files with an extension that starts with logs.
#-exec;
#rm -rf: forcibly delete files, including directories;
#{} \ : put the result of find inside;
Copy the code

About the crontab can refer to: www.cnblogs.com/zoulongbin/…