shell中可以是直接对比日期大小
[root@node5 test]# [ 2022-05-30 < 2022-06-08 ] && echo yes || echo no yes [root@node5 test]# [ 2022-05-30 < 2022-06-08 ] && echo yes || echo no yes
所以脚本可以这样写:
[root@node5 test]# cat del_time_dir.sh
#!/bin/bash
set -e
time=$(date -d '10 days ago' +"%F")
for dir in `ls -rt /root/test/ | awk '{print $NF}'`;do
if [ $dir < $time ];then
rm -rf /root/test/$dir
echo "$dir has been deleted"
fi
done



