linux 定期清除日志

clearLog.sh

  #!/bin/sh
  find /usr/local/apache/logs -mtime + 30 -name "*.log" -exec rm {} \;

    说明:

    1. find:Linux查找命令,用户查找指定条件的文件
    2.  /usr/local/apache/logs:需要进行清理的目标目录
    3.  -mtime:标准语句写法
    4.  +30 :数字代表天数   选中30天外的数据
    5.  -name "*.log":目标文件名
    6.  -exec:固定写法 执行rm命令
    7.  rm :强制删除包括目录在内的文件
    8.  {} \;:固定写法,一对大括号+空格+\+;

chmod +x clearLog.sh

crontab 启动定时任务

猜你喜欢

转载自www.cnblogs.com/lizhang4/p/9283333.html
今日推荐