删除超过一定时间的日志
2014-04-25 00:00
507 查看
find . -name '*log*' -type f -mtime +1 | xargs rm
Actually, date ranges in the find command do not work quite how you expect them to.
1 means 24 hours old
-1 means less than 24 hours old
+0 means more than 24 hours old
+1 means more than 48 hours old
Demonstration at the ksh prompt...
Code:
The reason is that "+1" means 2 or more days old, i.e. more than 48 hours old.
if you need to be really precise I usually do summink like:
Code:
Actually, date ranges in the find command do not work quite how you expect them to.
1 means 24 hours old
-1 means less than 24 hours old
+0 means more than 24 hours old
+1 means more than 48 hours old
Demonstration at the ksh prompt...
Code:
$ for i in 09 10 11 12;do touch -t 200707${i}0000 July_${i};done $ ls -o total 0 -rw-r--r-- 1 Ygor 0 Jul 9 00:00 July_09 -rw-r--r-- 1 Ygor 0 Jul 10 00:00 July_10 -rw-r--r-- 1 Ygor 0 Jul 11 00:00 July_11 -rw-r--r-- 1 Ygor 0 Jul 12 00:00 July_12 $ for j in 1 -1 +0 +1;do echo "[[ ${j} ]]";find . -type f -mtime ${j} -print;done [[ 1 ]] ./July_11 [[ -1 ]] ./July_12 [[ +0 ]] ./July_09 ./July_10 ./July_11 [[ +1 ]] ./July_09 ./July_10
The reason is that "+1" means 2 or more days old, i.e. more than 48 hours old.
if you need to be really precise I usually do summink like:
Code:
touch -t YYYYMMDDhhmmss 111 find . -older 111 | xargs rm
相关文章推荐
- remedy定期删除超过一定时间的流转垃圾数据
- 启用mysql日志记录执行过的sql并且开启慢查询记录所有超过慢查询时间的SQL以及未使用索引SQL
- 打印log4j日志 : 超过一定大小新建日志文件 & 每天新建一个日志文件
- android开发常用的缓存策略详解(3)- 缓存中的时间超过我们设定的值,将其删除
- 在window 2003中删除一定时间内文件的批处理
- localstorge的缓存写法(超过一定时间自动清空)
- shell脚本删除指定目录下超过指定时间的文件
- windows下定期清理超过一定时间的文件
- [转载]python脚本删除一定时间以外的文件
- java程序中如何为一个while(true)循环计时,超过一定时间比如10个小时就退出循环?
- 删除指定日期前的日志文件,对大于一定内存的日志文件重命名且新建日志继续写入
- powershell 删除目录内所有文件修改时间超过timeOutDay的文件。
- Oracle数据库案例整理-删除和停止Oracle数据库失败-归档日志超过最大值
- mtklog 日志到一定条件自动删除
- 自动删除指定时间内的日志和文件shell脚本
- DevExpress AspxGridView列超过一定数量更新和删除不起作用解决(AccessDataSource配置数据源时别图省力选*)
- UNITY3D C#热点测试打印函数调用超过一定时间的调用
- NGUI 鼠标停留UI上时缓慢显示子Item,当无停留超过一定时间后回到原地
- shell删除超过指定时间的文件
- 工具——ultraedit 删除输出日志中的时间头部分