BASH-搜索具有特定模式的目录中存在的特定模式的文件-RECURSIVELY



我要求编写一个脚本,以递归方式搜索与模式".foo"匹配的文件,但只搜索与同一模式".foo"匹配的目录中存在的文件。我试过:脚本名称:search_for_foo

function foo_search {
 while read line; do
    echo "$line”   
 done < "$1"
 }
 for file in ${*:1}; do
  if [[ $file == *.foo* ]]; then
    if [[ -f "$file" ]]; then
       foo_search $file
       fi
       if [[ -d "$file" ]]; then
       search_for_foo $file/*
       fi
    fi
    done <"$1"

它必须这样工作:/search_for_foo--some_file--

提前感谢

你的意思是吗

find -path "*foo/*/foo"
location=$1
pattern=$2
dir=$(find $location -type d -name "*.$pattern")
ls -lrt $dir|grep ^- |awk '{print $NF}'

像跑步一样/script.sh/location/didirectory/pattern

最新更新