Linux uses find to find files that last modified longer than three days and move to the specified directory

Source: Internet
Author: User

Usage scenarios: applications, such as Tomcat, generate new log files on a daily basis, taking a long time to consume a large number of disks and need to clean up these files on a regular basis.


The code is as follows:

Find/tomcat/logs/*.log-ctime +3-exec MV {}/tmp

You can also use Xargs to pass parameters

Find/tomcat/logs/*.log-ctime +3 | Xargs MV {}/tmp

Description: Moves a log file that has not been modified for more than 3 days in the specified directory to TMP.


If you want to delete it directly, change the command to the following:

Find/tomcat/logs/*.log-ctime +3-exec rm {} \;


Then set up scheduled tasks on the server and automatically clean up useless log information on a daily basis.


Linux uses find to find files that last modified longer than three days and move to the specified directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.