bash 如何在所有子目录中查找所有同名文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6470258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:14:51  来源:igfitidea点击:

how do i find all files with the same name in all subdirectories

linuxbashfilesystemsfindfile-globs

提问by loosecannon

I want to find all the different .gitignore files I have to combine them into one.

我想找到所有不同的 .gitignore 文件,我必须将它们合二为一。

I tried something like find */**/.gitignorebut that came up with nothing.

我尝试了类似的东西,find */**/.gitignore但没有任何结果。

All the files are in sub directories of my current dir, as well as the current directory.

所有文件都在我当前目录的子目录中,以及当前目录中。

I am using Bash on linux

我在 linux 上使用 Bash

回答by sehe

find -name .gitignore

That should do

那应该做

Since you are using bash:

由于您使用的是 bash:

shopt -s globstar
echo **/.gitignore

From man bash:

来自man bash

   globstar
          If set, the pattern ** used in a pathname expansion context will match a
          files and zero or more directories and subdirectories.  If the pattern is
          followed  by  a /, only directories and subdirectories match.

回答by Rahul

Try this

尝试这个

find /home/user1 -name 'result.out' 2>/dev/null

In your case

在你的情况下

find /<your DIR> -name '*.gitignore' 2>/dev/null

This results in

这导致

/home/user1/result.out
/home/user1/dir1/result.out
/home/user1/dir2/result.out