如何查找所有子目录中具有相同名称的所有文件

发布于 2024-11-17 04:36:57 字数 160 浏览 4 评论 0原文

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

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

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

我在 Linux 上使用 Bash

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

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

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

I am using Bash on linux

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太阳男子 2024-11-24 04:36:57
find -name .gitignore

应该可以,

因为您使用的是 bash:

shopt -s globstar
echo **/.gitignore

来自 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.
find -name .gitignore

That should do

Since you are using bash:

shopt -s globstar
echo **/.gitignore

From 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.
寄居人 2024-11-24 04:36:57

试试这个

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

在你的情况下

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

这会导致

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文