shell编程-定时删除(30天)文件

1.创建shell

touch /opt/auto-del-30-days-ago.sh

chmod +x auto-del-30-days-ago.sh

2.编辑shell脚本:

vi auto-del-30-days-ago.sh

编辑内容如下:

#!/bin/sh

find /opt/soft/log/ -mtime +30 -name "*.log" -exec rm -rf {} ;

分析:

  1.  /opt/soft/log/---为要定时删除文件的文件目录
  2.  -mtime +30   为大于30天以上
  3. -name  "*.log"  为文件名称 模糊匹配*
  4. -exec  执行
  5. rm -rf {} ;  删除上面匹配到的文件
原文地址:https://www.cnblogs.com/zyy98877/p/10120766.html