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 閱讀(319) 評論(0)  編輯  收藏 所屬分類: Linux

          主站蜘蛛池模板: 肥西县| 文登市| 长汀县| 凌源市| 东丽区| 德格县| 宣汉县| 泸溪县| 哈巴河县| 瑞丽市| 永寿县| 威信县| 福贡县| 拉孜县| 兖州市| 乌海市| 乐业县| 九江市| 东城区| 苍山县| 陈巴尔虎旗| 英吉沙县| 呼伦贝尔市| 威远县| 金乡县| 五家渠市| 洞口县| 金昌市| 崇礼县| 白玉县| 合作市| 读书| 富川| 顺平县| 大邑县| 克拉玛依市| 枞阳县| 凤凰县| 大庆市| 抚宁县| 冕宁县|