您的位置:首页 > 其它

练习2:保留每月1号 每周一 7天内文件

2016-12-02 08:49 134 查看
#保留每月1号 每周一 7天内

cd $backPath

filelist=`ls $backPath/`

for f in $filelist

do

   filename=$f

   cutfile=`echo $filename |cut -c1-3`

   cuttime=''

  if [ "$cutfile" = "saf" ]; then

       cuttime=`echo $filename |cut -c7-14`

  elif [ "$cutfile" = "upl" ]; then 

      cuttime=`echo $filename |cut -c11-18`

  else
echo ""

  fi

  chuyi=`echo $cuttime |cut -c7-8`

  if [ "$chuyi" = "01" ]; then
echo $filename'chuyi======'

        continue

  fi

  xinqi=`date -d $cuttime +%w`

  if [ "$xinqi" = "1" ]; then

       echo $filename'xinqiyi===='

       continue

   fi

 sevenday=`date -d '-7 day' +%Y%m%d`

if [ "$cuttime"  -gt  "$sevenday" ]; then

  echo $filename'serverday======'

   continue

 fi

rm -rf $backPath/$filename

 

done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: