Linux编程实现递归查找文件
程序员文章站
2022-05-03 10:46:08
命令格式如下:SCRIPT_NAME SEARCH_ON_DIR SEARCH_FILENAME 1 #!/bin/bash 2 Find(){ 3 echo $3" "$1 4 files=`ls $1` 5 for file in $files 6 do 7 if [ -d $1"/"$file ......
命令格式如下:
script_name search_on_dir search_filename
1 #!/bin/bash 2 find(){ 3 echo $3" "$1 4 files=`ls $1` 5 for file in $files 6 do 7 if [ -d $1"/"$file ] 8 then 9 find $1"/"$file $2 `expr $3 + 1` 10 elif [ $file=$2 ] 11 then 12 echo $1"/"$2 13 fi 14 done 15 } 16 findfile(){ 17 if [ -d $1 ] 18 then 19 find $1 $2 0 20 else 21 echo "this is not a directory or does not exist" 22 fi 23 } 24 echo "start finding $2 in $1" 25 findfile $1 $2
基本实现简单查找功能,编写代码时应格外注意语法格式