文件夹以时间命名,比如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
来源:51CTO
作者:lukacs
链接:https://blog.51cto.com/14545987/2439215