用递归的方法在linux下遍历一个目录

代码如下:

#!/bin/sh

dosth()
{
#...
}

#遍历目录
dirlist()
{
dosth $1
for subitem in `ls $1`
do
if [ -d "$1/$subitem" ]
then
dirlist $1/$subitem
elif [ -f "$1/$subitem" ]
then
dosth $1/$subitem
fi
done
}

[ $# = 0 ] &

for i in `ls $1`
do
if [ -d "$1" ]
then
dirlist $1
fi
done

关键字:遍历 递归 linux目录

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

您正在使用您的 WordPress.com 账号评论。 注销 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 注销 /  更改 )

Connecting to %s