#!/bin/bash
cd /home/wanggy/rmfile/
ls -l | grep ^d |
linuxjishu/13830.html target=_blank class=infotextkey>awk '{print $NF}' >/home/wanggy/tmp
cat /home/wanggy/tmp |while read dir1
do
cd $dir1
echo "第一级目录 $dir1"
ls -l | grep ^d | awk '{print $NF}' >/home/wanggy/tmp1
cat /home/wanggy/tmp1 |while read dir2
do
echo "二级目录 $dir2"
cd $dir2
#对大于2012年的目录再判断,小于则直接删除。
if [ $dir2 -gt 2011 ];then
ls -l | grep ^d | awk '{print $NF}' >/home/wanggy/tmp2
cat /home/wanggy/tmp2 |while read dir3
do
#9月份之前的删除"
if [ $dir3 -lt 09 ];then
rm -rf $dir3
fi
done
else
echo "删除2012前的目录:$dir2"
rm -rf $dir2
fi
#返回上一级
cd ..
done
#返回上一级
cd ..
done