so true

          心懷未來,開創未來!
          隨筆 - 160, 文章 - 0, 評論 - 40, 引用 - 0
          數據加載中……

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

          #!/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

          說明: 其實用find就可以,只要指定-maxdepth即可,這里只為練練手

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

          主站蜘蛛池模板: 禄劝| 凤城市| 车险| 台南县| 绿春县| 临猗县| 繁峙县| 屯昌县| 沈丘县| 锡林浩特市| 年辖:市辖区| 诸暨市| 麻江县| 大安市| 石渠县| 招远市| 五峰| 会昌县| 德江县| 阿图什市| 大厂| 铜川市| 乐昌市| 揭东县| 合江县| 桂阳县| 华安县| 东至县| 莫力| 南投市| 合山市| 辽中县| 盱眙县| 门头沟区| 德昌县| 嘉义县| 陇川县| 彰化县| 江都市| 双柏县| 广灵县|