Shell deletes objects before a specified time.
Since the recent World Cup, I have been busy with work and the World Cup, and I have no time to manage my blog. Today, I can only give you a simple little shell. the company asked to delete the backup file one month ago, so that the hard disk would not be cracked. After reading the file on the server, the backup files for three months had not been cleared, fortunately, it is SQL backup, or the hard disk space will be full long ago.
The following is my solution:
Cat delbak. sh
1
#!/bin/sh
2
location=
"/root/sqlbak/"
3
find
$location -mtime +30 -
type
f |
xargs
rm
-f
Ps:
Location is the directory for searching.
-- Mtime + 30 is set to 30 days ago
-Type f: the type found this week is file.
Add crontab to delete
Crontab-l
10 4 1 **/bin/sh/root/soft_shell/delbak. sh
It is set to execute the script at 04:10 on the first day of every month. Of course, you can also perform the script according to your own needs.
The same deletion method:
1
find
/root/sqlbak -mtime +30 -
type
f -name *.gz -
exec
rm
-f {} \;