shell delete files before the appointed time

Recently World Cup to has, has been busy work and World Cup Zhijian, are no empty to tube tube I of blog has, today only whole simple of small Shell to everyone has. company requirements delete a months zhiqian of backup file, lest put hard disk to whole burst has, Shang server see has Xia, actually are has 3 months of backup no cleanup has, OK is SQL backup, or hard disk space early full has.

Here is my solution:

find $location -mtime +30 -type f |xargs rm -f

The directory location is set up to find
–Mtime +30 is set for 30 days ago
-Type f this week to find type for files

Then add in crontab time to remove
crontab -l
10 4 1 * * /bin/sh /root/soft_shell/

As 1th each month 4:10 for Scripting setting. of course, you can according to your own needs.

The same removal method:
find /root/sqlbak -mtime +30 -type f -name *.gz -exec rm -f {} \;

Leave a Reply

Your email address will not be published. Required fields are marked *