发表于 2018-8-27 06:12:00

shell脚本删除N天前的文件夹

#! /bin/bashhistoryDir=~/test/  
today=$(date +%Y-%m-%d)echo "---------today is $today-----------"tt=`date -d last-week +%Y-%m-%d`echo "next is to delete release before $tt"tt1=`date -d $tt +%s`#小于此数值的文件夹删掉#echo $tt1 for file in ${historyDir}*do
  
    if test -d $file
  
      then
  
      name=`basename $file`      #echo $name
  
      curr=`date -d $name +%s`      if [ $curr -le $tt1 ]            then
  
                echo " delete $name-------"
  
                rm -rf ${historyDir}${name}
  
      fi
  
    fidone1234567891011121314151617181920212212345678910111213141516171819202122


页: [1]
查看完整版本: shell脚本删除N天前的文件夹