删除目录下(包括子目录)某天的文件

#!/bin/bash
DATE10=$(date -d "10 days ago"  +%F)
WEBPATH="/root/test/file"

function rmLongerFile(){
      fileInfo=$(stat $1 | grep -i 'Modify' | grep $DATE10)
     if [ -z "$fileInfo" ];
        then
           echo $1"  [file date not match "$DATE10" not need remove]";
        else
           echo $1"  [file date match "$DATE10" should need remove]";
           rm -rf $1
     fi         
}

function findFile(){
        for file in `ls $1`
        do
          if [ -d $1"/"$file ];
          then
                findFile $1"/"$file;    
          else
                rmLongerFile $1"/"$file;                
          fi
        done
}

findFile $WEBPATH

你可能感兴趣的:(运维)