shell监控文件夹大小

#限制的容量大小单位k
cap=1784
#当前的文件夹容量大小
curcap=`du -sk|awk '{print $1}'`
#暂存遍历的单个文件大小
size=0
for file in `ls -l|awk {'print $9'}`
        do
                if [ -f $file  ];  then
                        size=`du -sk $file | awk '{print $1}'`
                        if [[ $curcap -gt $cap ]] ; then
                                ((curcap =curcap-size))
                                echo $curcap
                        fi
                fi
done

猜你喜欢

转载自jadeluo.iteye.com/blog/2272105