shell清除大于30天的文件

shell清除大于30天的文件,如果文件数量小于7个则不进行删除
删除的同时需要指定文件夹,log日志存放路径,
待删除的文件后缀

#!/bin/bash
#待删除的文件路径数组
#locations=(
#	/home/cxy/test 
#	/home/cxy/test2 
#	/home/cxy/test3
#)

locations=(
       /home/cxy/test
)


#输出的文件路径
myfile=/home/cxy/test/myfile.txt

#循环路径
for ((j = 0; j <  ${#locations[*]}; j = j+ 1))
do
#具体路径
location=${locations[$j]}
#echo $location
file=`find $location -mtime +30 -print`
fileCount=`find $location -mtime +30 -print | wc -l`

   if [ $fileCount -le 7 ]
   then
	echo $fileCount
	exit
   fi

   for i in $file
   do
	#待删除文件的格式
	if [ "${i##*.}"x = "txt"x ]||[ "${i##*.}"x = "css"x ]
	then
	   time1=$(date "+%Y-%m-%d %H:%M:%S")
	   #  echo ${time1}
	   #  echo ${i}
	   echo "时间:${time1},文件路径:${i}" >> ${myfile}
	   #rm -r $i
	fi
   done

done
echo "successful"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值