清理linux 某个文件夹下面所有的log文件
#!/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文件的更多相关文章
- 如何在linux系统下对文件夹名有空格的文件夹进行操作
http://www.2cto.com/os/201409/335119.html 在Windows操作系统中可以轻易地创建\移动\删除文件夹名带有空格的文件夹, 而在linux则需要进行一些特殊的处 ...
- linux 系统获得当前文件夹下存在的所有文件 scandir函数和struct dirent **namelist结构体[转]
linux 系统获得当前文件夹下存在的所有文件 scandir函数和struct dirent **namelist结构体 1.引用头文件#include<dirent.h> struct ...
- shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹
shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...
- 将文件夹下的所有csv文件存入数据库
# 股票的多因子分层回测代码实现 import os import pymysql # import datetime, time # from config import * database_ta ...
- python判断文件和文件夹是否存在、创建文件夹
>>> import os >>> os.path.exists('d:/assist') True >>> os.path.exists('d: ...
- python实现将大文件夹分割成多个子文件夹
楼主用的linux,一旦数据达到几万,文件夹打开就会变卡,同时也方便同时分工协作,便于git管理,写了个将大文件夹分割成多个小文件夹的脚本 如操作文件夹:img,脚本不破坏img的数据,创建img_1 ...
- python 判断文件和文件夹是否存在、创建文件夹
原文链接:https://www.cnblogs.com/hushaojun/p/4533241.html >>> import os >>> os.path.ex ...
- 用字符流实现每个文件夹中创建包含所有文件信息的readme.txt
package com.readme; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; i ...
- 在文件夹中 的指定类型文件中 查找字符串(CodeBlocks+GCC编译,控制台程序,仅能在Windows上运行)
说明: 程序使用 io.h 中的 _findfirst 和 _findnext 函数遍历文件夹,故而程序只能在 Windows 下使用. 程序遍历当前文件夹,对其中的文件夹执行递归遍历.同时检查遍历到 ...
随机推荐
- ntpdate设置
ntpdate设置 学习了:https://www.cnblogs.com/ibnode/p/3573302.html http://www.blogjava.net/spray/archive/20 ...
- java中boolean与字符串或者数字1和0的转换
mysql有个字段是bit,只存储1和0,是二进制存储,那么在java的dao层如何映射成boolean呢 @Column(name="is_standard") private ...
- Silverlight 之 断点调试
silverlight程序经常会遇到无法调试的情况,下面来总结解决方案. 一.问题描述 在Silverlight开发过程中,经常时不时的会碰到Silverlight无法调试的问题.如下几种情况: 1. ...
- berkelydb学习
http://www.oracle.com/technetwork/cn/java/seltzer-berkeleydb-sql-085418-zhs.html 官网中文学习网址
- 寻找SQL注入点
如果要对一个网站进行SQL注入攻击,首先就需要找到存在SQL注入漏洞的地方,也就是寻找所谓的注入点.可能的SQL注入点一般存在于登录页面.查找页面或添加页面等用户可以查找或修改数据的地方. 最常用的寻 ...
- jQuery实现页面关键词高亮
示例代码,关键位置做了注释,请查看代码: <html> <head> <title>jQuery实现页面关键词高亮</title> <style ...
- linux下sar tool command note
linux下的sar工具简介 我习惯使用的命令是 : sar -r -f /var/log/sa/sa24 sar 既能报告当前数据,也能报告历史数据 不带选项执行会以10分钟为间隔报告自午夜 ...
- ORACLE-SQL(一)
迁移时间:2017年6月1日10:02:43 CreateTime--2017年6月1日09:59:30Author:Marydon 一.SQL语句 (一)基础篇 1.1.1 where 子句 1 ...
- SettingsTortoiseSVN
迁移时间:2017年5月20日11:16:05CreateTime--2016年9月18日18:20:15Author:Marydon在windows下安装SVN软件 说明:64位的系统只能安装6 ...
- properties转yml
分享一个在线properties 转 yml工具,也支持yml转properteis: http://toyaml.com/ 域名非常好记:to yaml .com yml,即yaml文本格式文件的后 ...