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 {} \;  删除上面匹配到的文件

 

posted @ 2018-12-14 17:52  定静沉行  阅读(1707)  评论(0编辑  收藏  举报