shell删除指定时间之前的文件

cat delbak.sh
1#!/bin/sh
2location="/root/sqlbak/"
3find $location -mtime +30 -type f |xargs rm -f


ps:
location 是设置查找的目录
--mtime +30 是设置时间为30天前
-type f 这周查找的类型为文件

然后加入crontab定时来删除
crontab -l
10 4 1 * * /bin/sh /root/soft_shell/delbak.sh

设定为每个月1号晚上4点10分执行脚本.当然你也可以根据你自己的需求去整.

相同的删除方法:
1find /root/sqlbak -mtime +30 -type f -name *.gz -exec rm -f {} \;
posted @ 2014-09-16 15:59  doubtwalker  阅读(973)  评论(0编辑  收藏  举报