zoukankan      html  css  js  c++  java
  • 清理linux 某个文件夹下面所有的log文件

    #!/bin/sh
    #目标文件夹下面所有问题
    target_dir="/app/"
    #删除2天前新建的后缀为log的文件
    find /app/applog*/ -ctime +2 -name "*.log" -exec rm -rf {} ;
    #查找出文件夹下所有的log文件
    list=`find $target_dir  -name "*.log"`
    for file in $list 
    do
        if test -f $file
            then 
            #清理   
            cat /dev/null > $file
            ls -l $file
        fi
    done
    df

     第二种,会有显示,好用点

    #!/bin/sh
    #配置目标文件夹
    target_dir="/app/"
    #find $target_dir -ctime +2 -name "*.log" -exec ls -l {} ;
    #直接删除
    #find $target_dir -ctime +2 -name "*.log" -exec rm -rf {} ;
    # 先在目标目录下查找出最后修改时间为2天前的,并且后缀为.log的文件  再循环删除日志文件
    list=`find $target_dir -mtime +2 -name "*.log"`
    for dele_file in $list
    do
        if test -f $dele_file
            then
            pwd_info=`ls -l $dele_file`
            rm -rf $dele_file
           echo "删除文件:"$pwd_info
        fi
    done
    #先查找出 目标目录下所有的后缀为.log 的文件,再循环清空日志
    list=`find $target_dir  -name "*.log"`
    for file in $list 
    do
        if test -f $file
           then        
           cat /dev/null > $file
           pwd_info=`ls -l $file`
           echo "清空文件:"$pwd_info
        fi
    done
  • 相关阅读:
    httpclient妙用一 httpclient作为客户端调用soap webservice(转)
    WebService学习总结(转)
    C++的override和final
    C++类const和static成员初始化
    C++数据存储方式
    C++类成员存储大小
    内联函数
    C++接口的概念
    C++深拷贝和浅拷贝
    C++构造函数以及何时被调用
  • 原文地址:https://www.cnblogs.com/testway/p/7308724.html
Copyright © 2011-2022 走看看