Requirements: Delete files, directory structure: ip/year/month, everyone has a copy of this directory now need to delete all files before 2012, 2012 after the deletion of a specific month.
Originally wanted to use find, the results found that these file time (A,M,C) records are not originally generated.
No way to have to think of a soil method to traverse, who has a good method, welcome to inform.
Copy Code code as follows:
#!/bin/bash
cd/home/wanggy/rmfile/
Ls-l | grep ^d | awk ' {print $NF} ' >/home/wanggy/tmp
Cat/home/wanggy/tmp |while Read Dir1
Todo
CD $dir 1
echo "First level directory $dir 1"
Ls-l | grep ^d | awk ' {print $NF} ' >/HOME/WANGGY/TMP1
CAT/HOME/WANGGY/TMP1 |while Read Dir2
Todo
echo "Level two directory $dir 2"
CD $dir 2
#对大于2012年的目录再判断, less than is deleted directly.
If [$dir 2-gt];then
Ls-l | grep ^d | awk ' {print $NF} ' >/HOME/WANGGY/TMP2
CAT/HOME/WANGGY/TMP2 |while Read Dir3
Todo
#9月份之前的删除 "
If [$dir 3-lt];then
RM-RF $dir 3
Fi
Done
Else
echo "Delete directory before 2012: $dir 2"
RM-RF $dir 2
Fi
#返回上一级
Cd..
Done
#返回上一级
Cd..
Done