#!/bin/sh
#目标文件夹下面所有问题
target_dir="/app/"
#删除2天前新建的后缀为log的文件
find /app/applog*/ -ctime + -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 + -name "*.log" -exec ls -l {} \;
#直接删除
#find $target_dir -ctime + -name "*.log" -exec rm -rf {} \;
# 先在目标目录下查找出最后修改时间为2天前的,并且后缀为.log的文件 再循环删除日志文件
list=`find $target_dir -mtime + -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

清理linux 某个文件夹下面所有的log文件的更多相关文章

  1. 如何在linux系统下对文件夹名有空格的文件夹进行操作

    http://www.2cto.com/os/201409/335119.html 在Windows操作系统中可以轻易地创建\移动\删除文件夹名带有空格的文件夹, 而在linux则需要进行一些特殊的处 ...

  2. linux 系统获得当前文件夹下存在的所有文件 scandir函数和struct dirent **namelist结构体[转]

    linux 系统获得当前文件夹下存在的所有文件 scandir函数和struct dirent **namelist结构体 1.引用头文件#include<dirent.h> struct ...

  3. shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹

    shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...

  4. 将文件夹下的所有csv文件存入数据库

    # 股票的多因子分层回测代码实现 import os import pymysql # import datetime, time # from config import * database_ta ...

  5. python判断文件和文件夹是否存在、创建文件夹

    >>> import os >>> os.path.exists('d:/assist') True >>> os.path.exists('d: ...

  6. python实现将大文件夹分割成多个子文件夹

    楼主用的linux,一旦数据达到几万,文件夹打开就会变卡,同时也方便同时分工协作,便于git管理,写了个将大文件夹分割成多个小文件夹的脚本 如操作文件夹:img,脚本不破坏img的数据,创建img_1 ...

  7. python 判断文件和文件夹是否存在、创建文件夹

    原文链接:https://www.cnblogs.com/hushaojun/p/4533241.html >>> import os >>> os.path.ex ...

  8. 用字符流实现每个文件夹中创建包含所有文件信息的readme.txt

    package com.readme; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; i ...

  9. 在文件夹中 的指定类型文件中 查找字符串(CodeBlocks+GCC编译,控制台程序,仅能在Windows上运行)

    说明: 程序使用 io.h 中的 _findfirst 和 _findnext 函数遍历文件夹,故而程序只能在 Windows 下使用. 程序遍历当前文件夹,对其中的文件夹执行递归遍历.同时检查遍历到 ...

随机推荐

  1. Redis自学笔记 --Hash、List、Set类型简述

    Hash类型                                                                                    hset key f ...

  2. 敏捷开发方法XP的12个最佳实践

    极限编程(eXtreme Programming,简称XP)是一种轻量级.高效.低风险.柔性.可预测的.科学的软件开发方法,其特性包含在12个最佳实践中. 1.  计划游戏 ( Planning Ga ...

  3. 取消Eclipse SVN的自动链接方式

    1. 选中指定的项目名(有文件夹样子的那个) 2. 右键,在在弹出菜单选择 Team 3. 然后再点击, Disconnect 即可.

  4. 用Bluepages来验证intranetId和Password的有效性

    代码很简单,如下: int ret = -1;ReturnCode rc = null;            cwa2 cw = new cwa2();rc = cw.authenticate(in ...

  5. asp.net网站项目调用page,或者ashx页面不能用反射

    public class TestHandler : System.Web.IHttpHandler { public bool IsReusable { get { return false; } ...

  6. 解决pl/sql 查询数据中文显示成?

    解决方法: 1.打开 PLSQL Developer 安装目录下,看到有PLSQLDev.exe的目录, 在PLSQL Developer文件夹内新建“PLSql_run.bat”文件,在该文件中输入 ...

  7. jQuery ajax - ajax() 方法详解

    一些代码通过jQuery来做ajax异步提交. //验证昵称是否存在 function checkNickNameIsExist(){ var nickName = jQuery("#nic ...

  8. 理解并使用.NET 4.5中的HttpClient(转)

    原文地址:http://www.cnblogs.com/wywnet/p/httpclient.html HttpClient介绍HttpClient是.NET4.5引入的一个HTTP客户端库,其命名 ...

  9. RHEL和Centos常用版本

    学而优则仕,思则进步也Q Redhat: http://pan.baidu.com/s/1qXKRqqS Centos: http://pan.baidu.com/s/1o8RrjXw

  10. GridView显示数据鼠标悬停变色

    一. 首先在前台GridView中加上onrowdatabound="GridView1_RowDataBound": <asp:GridView ID="Grid ...