linux 获得目录下的文件及子文件的绝对路径

shell script

#!/usr/bin/bash
a_root="$1"

for sub in $(ls $a_root); do
	if [ -d ${a_root}/${sub} ]; then
		./SubfileAbsPath.sh ${a_root}/${sub}
	else
		echo ${a_root}/${sub}
	fi
done
./SubfileAbsPath.sh ~/home > path.log

简单粗暴,但是弊端太明显了


absPath() {
    local a_root="$1"

    for sub in $(ls $a_root); do
        if [ -d $a_root/$sub ]; then
            absPath $a_root/$sub
        else
            echo $a_root/$sub
        fi
    done
}

absPath "$1"

递归爆栈,?

8185 boom


find ~ -type f 完美

你可能感兴趣的:(shell)