Scripts for periodically deleting files from a day before Windows and Linux _dos/bat

Source: Internet
Author: User

Before the most time we are scheduled backup function, we often use the timing function to back up the site data or back up the database, I will give (www.jb51.net) you introduce a few Linux and Windows scheduled to delete a day before the file method, this and backup a bit different, But Datong is a small righteousness.

The contents of the Windows BAT file are as follows;

Copy Code code as follows:

@echo off
Forfiles-p "D:\servers\apache2.2\logs"-s-m *.log-d -15-c "cmd/c del @path"
Forfiles-p "D:\servers\mysql\logs"-s-m *.log-d -15-c "cmd/c del @path"

The above directory can be changed to the specified directory, *.log can filter the file format, the following-D parameter is a negative number of days before, a positive number is how many days after. Save it as a bat file, and then set the time to execute daily on the Windows planning task.

The contents of the shell file under Linux are as follows:

Copy Code code as follows:

#!/bin/bash
# Delete files from 30 days ago
find/var/usr/nginx/logs/-mtime +30-type f-name \*.gz | Xargs rm-f

The same as the above directory for their own designated directory, the following \*.gz represents the file name extension,-mtime the following parameters and windows above the opposite, a positive number of days before the file. Save the above content as. SH and use chmod +x to set up executable permissions, and then put them into a timed task to execute.

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.