【问题标题】:how do i find all files with the same name in all subdirectories如何在所有子目录中找到所有同名文件
【发布时间】:2011-06-24 15:41:24
【问题描述】:

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

我尝试了find */**/.gitignore 之类的方法,但结果一无所获。

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

我在 linux 上使用 Bash

【问题讨论】:

    标签: linux bash filesystems find file-globs


    【解决方案1】:
    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.
    

    【讨论】:

    • (a) 试试看 (b) man bash。它设置 shell 选项,这次是 'globstar'
    • ,外壳选项?这是一个猜测
    • 哦哈哈,我明白了,所以 globstar 集允许扩展 ** 或类似的东西?
    • bash: shopt: globstar: invalid shell option name,知道为什么会这样吗? (v3.2.39(1))
    • 如何解决这个错误bash: shopt: globstar: invalid shell option name??
    【解决方案2】:

    试试这个

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      • 2014-03-08
      • 2023-04-06
      • 2023-01-04
      • 1970-01-01
      相关资源
      最近更新 更多