linux delete files older than specified date

When es does not specify a log, it defaults to the log of var

 

Use >edf_cluster.log to clear the content of the current log file, and still keep the file name, only clear the content

 

Two methods:

1. Keep files of the last three months in a directory, and files older than three months will be automatically deleted.

find /email/v2_bak -mtime +92 -type f -name *.mail[12] -exec rm -rf {} \;

/email/v1_bak -- set the search directory;
-mtime +92 -- set the time to 91 days ago;
-type f --set the search type to file;
-name *.mail[12] --set the file name to include mail1 or mail2;
-exec rm -f --delete the operation after searching;
    After this command is written into crontab, the work of finding and deleting can be automatically completed.
2. Or use: find . -ctime +40 -type f | xargs rm -rf
 
1. Write the cleanup log script clear.sh
   #!/bin/sh
   find /opt/bak -mtime +6 -name "*.log" -exec rm {} \;
   find /opt/bak -mtime +6 -name "*.dmp" -exec rm {} \;
2. Authorize the script
    chmod +x clear.sh
3. Add scheduled tasks
    vi /etc/crontab
    Add at the end: 00 2 * * * root /opt/sh/clear.sh
4. Restart the crontab service

    service crond restart

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326126079&siteId=291194637