轮循遍历某个目录下所有文件包含子目录文件

来源:互联网 发布:淘宝清仓特卖真的吗 编辑:程序博客网 时间:2024/06/05 18:32
#!/bin/bash
##################
. /etc/profile
. ~/.bash_profile
##################


# 定义一个方法
foreachd(){
# 遍历参数1
for file in $1/*
do
# 如果是文件就打印处理,然后继续遍历,递归调用
        if [ -d $file ]
        then
#                echo $file
                foreachd $file
        else

                echo $file
        fi
done
}

# 执行,如果有参数就遍历指定的目录,否则遍历当前目录

if [[ ! -z $1 ]];then

    foreachd "$1"

else  

   foreachd `/bin/pwd`

fi
0 0
原创粉丝点击