linux定时删除文件脚本

#! /bin/sh
# 配置项
DEBUG=true
folderDir=/var/www/html/hlsrecord/
EXPIRE_DAY=1

# 过期时间和时间戳
deadTime=`date -d "-$EXPIRE_DAY day" +%Y-%m-%d`
$DEBUG && echo $deadTime
deadTimeStamp=`date -d $deadTime +%s`
$DEBUG && echo $deadTimeStamp

arrDir[0]='/var/www/html/hlsrecord/1126058978652760/2018-10-29'
arrDir[1]='/var/www/html/hlsrecord/1293636441140558/2018-10-28'
for dirPath in ${arrDir[*]}
# for file in `find /tmp -mindepth 2 -ctime +1 `
do
`$DEBUG && echo $dirPath`
folderName=`basename $dirPath`
`$DEBUG && echo $folderName`
#folder named by time, 2016-11-01
folderNameTimeStamp=`date -d $folderName +%s`
`$DEBUG && echo $folderNameTimeStamp`
if [ $folderNameTimeStamp -lt $deadTimeStamp ]
then
echo "Deleting folder: ${folderPath}/${folderName}"
# rm -rf ${dirPath}/${folderName}
fi
done
# 删除空文件夹
`find ${folderDir} -type d -empty -name '1*' | xargs rm -rf `

原文地址:https://www.cnblogs.com/swing07/p/9896684.html