so true

          心懷未來(lái),開創(chuàng)未來(lái)!
          隨筆 - 160, 文章 - 0, 評(píng)論 - 40, 引用 - 0
          數(shù)據(jù)加載中……

          列出某目錄下的所有目錄并且可以自由控制深度的腳本

          #!/bin/bash

          [ $# -gt 2 ] && {
              echo "Usage: ${0##*/} <dir=.> <deep=1>"
              exit 1
          }

          TOP=0
          QUEUELIST[${#QUEUELIST[@]}]=`cd ${1:-.};pwd`
          DEEPMAX=${2:-1}
          DEEP=0
          #The number of directories in the upper directory(DEEP-1)
          X=1
          #The number of directories in the next directory(DEEP+1)
          Y=0
          #The number of directories scanned in the current directory(DEEP)
          Z=0
          while [ $TOP -ne ${#QUEUELIST[@]} ]
          do
              curdir=${QUEUELIST[$TOP]}
              cd $curdir
              ((TOP++))
             
              for list in `ls`
              do
                  if [ -d $list ]
                  then
                      echo $curdir/$list
                      QUEUELIST[${#QUEUELIST[@]}]=$curdir/$list
                      ((Y++))
                  fi
              done
              ((Z++))
              if [ $Z -eq $X ];then
                  ((DEEP++))
                  if [ $DEEP -eq $DEEPMAX ];then
                      exit 0
                  fi
                  X=$Y
                  Y=0
                  Z=0
              fi
          done

          說(shuō)明: 其實(shí)用find就可以,只要指定-maxdepth即可,這里只為練練手

          posted on 2009-07-18 16:44 so true 閱讀(328) 評(píng)論(0)  編輯  收藏 所屬分類: Linux

          主站蜘蛛池模板: 镇雄县| 南京市| 威信县| 临颍县| 陇川县| 蒙山县| 涿鹿县| 吉林市| 青川县| 南投市| 张家口市| 崇义县| 察雅县| 开阳县| 喀什市| 贵定县| 安化县| 蒙山县| 禹城市| 安国市| 开江县| 博兴县| 连江县| 宽城| 安岳县| 哈尔滨市| 岢岚县| 会泽县| 开平市| 泗阳县| 古浪县| 黄冈市| 基隆市| 偃师市| 南投市| 中阳县| 龙岩市| 栖霞市| 甘泉县| 伊宁市| 出国|