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.