您的位置:首页 > 其它

删除超过一定时间的日志

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:

$ 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐