在系统上查找某些文件并在父目录 bash 中执行命令

1 bash shell cd exec find

我需要找到包含名为“thisfile”的文件的所有目录。找到文件后,我需要在包含文件的每个目录中执行某个命令。例如:查找包含“thisfile”的目录并列出每个目录中包含的所有文件。我正在尝试:find . -name "thisfile",然后我正在考虑将 cd 放入每个文件夹并执行命令,但我无法实现这一点。例如类似的东西find . -name "thisfile" -exec dirname && cd into those folders && ls"

Phi*_*ppe 5

您可以使用-execdir

find . -name "thisfile" -execdir ls \;
Run Code Online (Sandbox Code Playgroud)