标签:color nbsp bash done 很多 保留 today one 其他
每天在/home/face/capturepic/2017/目录下都会产生很多文件
/home/face/capturepic/2017/4/21
/home/face/capturepic/2017/4/22
希望的是每天只保留当天的文件夹,其他的文件夹删除
改写的.sh脚本如下
!/bin/bash dir="/home/face/capturepic/2017/" Available=`df -k | sed -n ‘/sda3/p‘ | awk ‘{print int($5)}‘` if [ $Available -gt 10 ];then echo "available less 10 " for mou in `ls $dir` do tmou=date +%m if [ $mou -lt $tmou ];then echo "delete dir $dir$mou " rm -rf $dir$mou elif [ $mou -eq $tmou ];then for day in `ls $dir$mou/` do today=date +%d if [ $day -ne $today ];then echo "delete dir $dir$tmou/$day " rm -rf $dir$tmou/$day fi done fi done fi
定时执行的corn文件如下(每分钟执行一次)
* * * * * ./test.sh
标签:color nbsp bash done 很多 保留 today one 其他
原文地址:http://www.cnblogs.com/baldermurphy/p/7658949.html