zoukankan      html  css  js  c++  java
  • linux系统&自动清理日志实现脚本

    文章来源:https://blog.csdn.net/lakelise/article/details/93711932

    编写清理脚本,添加到定时任务中:
    创建可执行文件
    cd /home
    touch clear_log.sh

    赋予可执行权限
    chmod +x clear_log.sh

    编写脚本内容
    vi clear_log.sh

    添加脚本
    #!/bin/sh
    find /home/zhongli_interface -type f -mtime +3 -name "*.tmp" -exec rm -rf {} ;


    /home/zhongli_interface 清理文件的路径
    -type f 清理文件类型为文件,f修改成d 就是文件夹
    -mtime +3 清理三天前的文件
    清理文件名为.tmp结尾的文件
    -exec 执行的命令
    {} ; 固定格式


    设置定时任务
    cd /etc
    crontab -e

    添加内容(每天陵城2点执行脚本)
    0 2 * * * /home/clear_log.sh

    保存退出
    ————————————————

    参数:

    实例命令 

        find /export/Logs/ -type f -name "*log*" -mtime +3 -exec rm -rf {} ;

        将/export/Logs/目录下所有30天前带".log"的文件删除。具体参数说明如下:

             find:linux的查找命令,用户查找指定条件的文件;

             /export/Logs/:想要进行清理的任意目录;

             -type f代表文件 d代表目录

             -mtime:标准语句写法;+30:查找30天前的文件,这里用数字代表天数;

             "*log*":希望查找的数据类型,"*.jpg"表示查找扩展名为jpg的所有文件,"*"表示查找所有文件,这个可以灵活运用,举一反三;

             -exec:固定写法;

             rm -rf:强制删除文件,包括目录;

             {} ; :固定写法,一对大括号+空格++;

             -size 查找符合大小的文件;
     

  • 相关阅读:
    LeetCode 264. Ugly Number II
    LeetCode 231. Power of Two
    LeetCode 263. Ugly Number
    LeetCode 136. Single Number
    LeetCode 69. Sqrt(x)
    LeetCode 66. Plus One
    LeetCode 70. Climbing Stairs
    LeetCode 628. Maximum Product of Three Numbers
    Leetcode 13. Roman to Integer
    大二暑假周进度报告03
  • 原文地址:https://www.cnblogs.com/flzs/p/11684287.html
Copyright © 2011-2022 走看看