Shell之删除某个路径下N前天的文件夹(时间命名)

匿名 (未验证) 提交于 2019-12-03 00:09:02

文件夹以时间命名,比如20190917。具体处理见下:
clean_export.sh

#!/bin/sh

#rm -rf /var/spool/postfix/maildrop/*

location="/data/tingyun/shared/data/application/export/"
dt=date +%Y%m%d -d "10 days ago"

for subdir in $(ls $location);
do
if [[ "${subdir}" < "${dt}" ]]; then
rm -rf ${location}${subdir} > /dev/null;

echo ${location}${subdir};

    echo "The directory(`date`)  ${location}${subdir} has been removed." fi

done

每天凌晨执行:

0 0 * /bin/bash /home/osoper/shellhome/clean_export.sh > /dev/null 2>&1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!