假如在一个文件夹下面有如下的很多目录,而每一个目录下面又有很多目录和很多文件,现在我们想只保留各个目录下面的文件,
Note: 其中文件rm_childDir.sh就是我们要执行的shell脚本.
那么,可以通过以下的shell程序实现我们想要的功能:
1 ####################################################
2 #Date:2014.8.12
3 #Author: Hero
4 #Function: delete the childdirectories when have many dirs
5 ####################################################
6 #!/bin/bash
7 for i in `ls .`
8 do
9 if [ -d $i ];then
10 cd $i
11 echo"**********************************************************"
12 echo "Have enter thedir:$i"
13 for j in `ls .`
14 do
15 if [ -d $j ];then
16 echo "$j is adir..!!"
17 rm -rf $j
18 fi
19 done
20 cd ..
21 else
22 echo "$i is not a dir,we are in current dir:`pwd`"
23 fi
24 echo "Have exit to the`pwd`"
25 echo "**********************************************************"
26 done