码迷,mamicode.com
首页 > 其他好文 > 详细

当日志文件大于1G时清空文件,非删除

时间:2019-02-28 15:18:25      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:exist   输出   txt   code   root   清空文件   日志   int   The   

#!/bin/bash
#当文件大于1G时清空

FILE=/root/hello.txt
#判断文件是否存在
if ! [ -f $FILE ]
then
#输出文件不存在
echo "file not exist!"
exit 1
fi
#判断文件大小,ls -l 用awk取输出的第五列
if [ ls -l $FILE|awk ‘{print $5}‘ -gt $((1024*1024)) ]
then
#输出空到文件中
echo " "> $FILE
fi

当日志文件大于1G时清空文件,非删除

标签:exist   输出   txt   code   root   清空文件   日志   int   The   

原文地址:https://blog.51cto.com/2225052/2356086

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!