shell 清理目录下 超过一段时间的数据。

递归删除过期文件,只删文件,不删目录。

#!/bin/bash
CACHE=/tmp/testClear
TIME_INTERVAL=300
function read_dir(){
    for file in `ls $1`
    do
       if [ -d $1"/"$file ]; then
         read_dir $1"/"$file
       else
         a=`stat -c %Y $1"/"$file`
         b=`date +%s`
         if [ $[ $b - $a ] -gt $TIME_INTERVAL ]; then
            echo "delete file:$1"/"$file"
            rm -rf $1"/"$file
         fi
       fi
    done
}
read_dir $CACHE
原文地址:https://www.cnblogs.com/whutqueqiaoxian/p/9685298.html