Linxu the file shell script before the specified time is deleted

Source: Internet
Author: User

Recently the World Cup has come, has been busy between work and the World Cup, there is no time to manage my blog, today can only be the whole simple small shell to everyone. The company asked to delete one months before the backup file, so that the hard drive to the whole explosion, on the server looked down, incredibly have 3 months of backup did not clean up, Fortunately, SQL backup, otherwise hard disk space is already full.

Here is my solution:

Cat delbak.sh

#!/bin/sh

location= "/root/sqlbak/"

Find $location-mtime +30-type f |xargs rm-f


Ps:

Location is the directory where you set up the lookup
--mtime +30 is set to a time of 30 days ago
-type F this week the type of lookup is a file

Then add the crontab timer to remove

Crontab-l
4 1 * */bin/sh/root/soft_shell/delbak.sh

Set to 1th per month to execute the script at 4:10 in the evening. Of course, you can do it according to your own needs.

The same deletion method:

Find/root/sqlbak-mtime +30-type f-name *.gz-exec rm-f {}\;

Related Article

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.