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"