文件夹以时间命名,比如20190917。具体处理见下:
date +%Y%m%d%H%M%S
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
参考:
https://www.cnblogs.com/eason-d/p/8603447.html