日期:2014-05-16  浏览次数:20745 次

linux shell 遍历指定目录下的所有文件夹

在linux 中,如何遍历指定目录下的所有文件夹呢?

要求能搜索结果中包含隐藏文件夹

脚本名:ergodic_folder.sh

脚本内容:

#!/bin/sh
list_alldir(){
    for file2 in `ls -a $1`
    do
        if [ x"$file2" != x"." -a x"$file2" != x".." ];then
            if [ -d "$1/$file2" ];then
                echo "$1/$file2"
                list_alldir "$1/$file2"
            fi
        fi
    done
}

list_alldir ./test
?

测试如下:

?

[root@localhost whuang]# ./ergodic_folder.sh

./test/.abc

./test/.abc/.ccc

./test/bbb


1 楼 DiaoCow 2013-01-08  
find ./test  -type d  实际工作发现,遍历目录时能用find就用find,速度会快很多