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
  • 相关阅读:
    C. Karen and Game
    BZOJ2134: 单选错位
    BZOJ3562: [SHOI2014]神奇化合物
    BZOJ1084: [SCOI2005]最大子矩阵
    BZOJ5039: [Jsoi2014]序列维护
    BZOJ1798: [Ahoi2009]Seq 维护序列seq
    BZOJ3932: [CQOI2015]任务查询系统
    BZOJ3339: Rmq Problem
    BZOJ3585: mex
    BZOJ4196: [Noi2015]软件包管理器
  • 原文地址:https://www.cnblogs.com/testway/p/7308724.html
Copyright © 2011-2022 走看看