Searchfile()
{
parentdir=$1
cd $parentdir
#如果是文件,则列出
filelist=$(ls -l|grep "^-"|awk '{print $9}')
for filename in $filelist
do
echo "$parentdir/$filename"
done
#如果是目录,递归遍历
dirlist=$(ls -l|grep "^d"|awk '{print $9}')
for dirname in $dirlist
do
cd $dirname
#curdir="$parentdir/$dirname"
curdir=$(pwd)
Searchfile "$curdir"
cd ..
done;
}
Searchfile '/root/test'
shell递归之遍历目录
最新推荐文章于 2024-09-23 16:48:02 发布