linux定时删除时间格式文件夹

linux定时删除时间格式文件夹 例如:20170809

#!/bin/bash

function deletedir(){
    ago_file=$(date -d '30 days ago' +%Y%m%d)
        dir_or_file=$1
        if [ -d $dir_or_file ]
        then
            for element_date in `ls $dir_or_file`
            do
                dir_or_file_date=$dir_or_file"/"$element_date
                if [ -d $dir_or_file_date ]
                then
                        date_file=$(date -d $element_date +%Y%m%d)
                        if [ $date_file -lt $ago_file ]
                        then
                                rm -rf $dir_or_file_date
                        fi
                fi
            done
        fi
}
root_dir="/data0/test"
deletedir $root_dir

猜你喜欢

转载自blog.csdn.net/zhangweibin123/article/details/80620464
今日推荐