shell脚本删除文件夹内上个月的文件

之前有脚本把日志转成excel,下个月开始删除上个月的

year=$(date -d "1 month ago" +"%Y")
month=$(date -d "1 month ago" +"%m")
folder="/usr/share/nginx/html/excel"
for file in `ls $folder`           
    do
        if [ -d $folder"/"$file ]
        then
           find  $folder"/"$file -name "$year-$month-*" -exec rm {} \;  
        fi
    done
posted @ 2024-02-18 09:16  朝阳1  阅读(192)  评论(0)    收藏  举报