#!/bin/sh location="/root/sqlbak/" find $location -mtime +30 -type f |xargs rm -rf
ps:
location 是设置查找的目录
--mtime +30 是设置时间为30天前
-type f 这周查找的类型为文件
然后加入crontab定时来删除
crontab -l
10 4 1 * * /bin/sh /root/soft_shell/delbak.sh
设定为每个月1号晚上4点10分执行脚本.当然你也可以根据你自己的需求去整.
相同的删除方法:
1 find /root/sqlbak -mtime +30 -type f -name *.gz -exec rm -f {} \;
删除文件
#!/bin/sh location="/root/sqlbak/" find $location -mtime +30 -type d |xargs rm -rf