Linux is called shell script to delete files

Source: Internet
Author: User

Writing Scripts

VI delbak.sh

The code is as follows :

#!/bin/sh

location= "/home/mysql/backup/"

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

explanation :

Location is the directory where the lookup is set
--mtime +7 is set to 7 days ago (delete files from location- specific directory 7 days ago )
-type f The type of lookup is file

The code is as follows :

#!/bin/sh

location= "/home/mysql/backup/"

Find $location-mtime +7-name "*.zip" |xargs RM-RF

-name "*.zip" to find files with a zip suffix for file names

timed Call Script

Direct Input Command:

Crontab-e Editing timed Tasks

Crontab-l Viewing timed Tasks

Crontab timed call script eg:

0 1 * * 1/bin/sh/home/mysql/backup/delbak.sh

Execute script delbak.sh every Monday wee 1 o ' Night

Questions:

If this is not possible, it may be a permissions issue, giving the script permission

chmod 777 delbak.sh

Linux is called shell script to delete files

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.