Bash Find Function Ubuntu-在目录树中查找与目录同名的文件

Bash Find Function Ubuntu-在目录树中查找与目录同名的文件,bash,ubuntu,find,Bash,Ubuntu,Find,我想在目录树中查找并打印文件,这些文件的目录名为sname 这是我目前的代码: #!bin/bash if [ $# -eq 0 ] then echo "No args" fi if [[ -d $1 ]] #if its dir then find $1 -type f | (while read var1 #for every regular file in dir tree do if [[ -f $var1 ]] t

我想在目录树中查找并打印文件,这些文件的目录名为sname

这是我目前的代码:

#!bin/bash
if [ $# -eq 0 ]
then
    echo "No args"
fi

if [[ -d $1 ]] #if its dir
then
    find $1 -type f | (while read var1 #for every regular file in dir tree
        do

        if [[ -f $var1 ]] 
        then
            echo $var1 #full path
            # I dont know how to get the dir name
            echo $(basename $var1) #file name
            echo

#then compare it and print full path
        fi
    done)
fi

我想在bash-linux中使用FIND函数来实现这一点。谢谢

您可以将此脚本与
查找一起使用:

while IFS= read -rd '' f; do
   d="${f%/*}"
   [[ ${d##*/} == ${f##*/} ]] && echo "$f"
done < <(find . -type f -print0)
而IFS=read-rd''f;做
d=“${f%/*}”
[${d##*/}=${f##*/}]&&echo“$f”

完成/usr/bin/find
;(除非使用该名称定义函数。)