#!/bin/bash
recdir()
{
for j in $@
do
    thisfile=$thisfile/$j
    if [ -f $thisfile ]
    then echo $thisfile
    elif [ -d $thisfile ]
    then 
    recdir $(command ls $thisfile) #若传进来的是一个目录这递归调用recdir
    fi
    thisfile=${thisfile%/*}  #当前的file处理完了后,截断它
done
}
recls()
{
for i in $@
do
    if [ -f $i ]
    then echo $i
    elif [ -d $i ]
    thisfile=$i
    then recdir $(ls $i)
    fi
done
}
if [ -z $1 ] 
    then recls .
else
    recls $@
fi

注:这里用了一个thisfile来表示完整目录 

转http://blog.csdn.net/zhoudaxia/article/details/4342316

posted on 2016-03-18 11:25  cjbourne  阅读(141)  评论(0)    收藏  举报