Shell scripts Delete backup file instances up to 30 days ago

Source: Internet
Author: User

According to company requirements, delete the server 30 days before the file, the following is the script:

#vi del-30.sh

#!/bin/bash

location= "/mpgdata/"

Find $location-type f-mtime +30-exec rm-f {} \;

#chmod +x del-30.sh


Description:/mpgdata/is the path to the find backup file.

-type f is the specified file type as a normal file.

-mtime +30 refers to a file that was 30 days ago.

-exec Rm-f means performing a silent deletion of the matching file.

It can be added to the automatic task so that it is automatically cleared.


#vi/etc/crontab

* * root/root/del-30.sh monthly 28th 11 o'clock 59 execution

: Wq

#service Crond Restart


This article is from the "Chen blog" blog, make sure to keep this source http://chenshengang.blog.51cto.com/4399161/1618629

Shell scripts Delete backup file instances up to 30 days ago

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.