當日志文件大於1G時清空文件,非刪除

#!/bin/bash
#當文件大於1G時清空bash

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
fiide

相關文章
相關標籤/搜索