【问题标题】:using find but only in subdirectories matching certain pattern使用 find 但仅在匹配特定模式的子目录中
【发布时间】:2013-06-14 09:19:47
【问题描述】:

我正在尝试构建我的 etags 文件。我有一个项目结构,给定一个根目录,有子目录,其中可以是名为“cpp”的目录。例如:

root
 - sub1
  - cpp
 - sub2
  - sub21
   - cpp
   - csharp

所以对于常规项目,我通常是这样的: 寻找 。 -type f ( -iname '.cpp' -o -iname '.hpp' -o -iname '.c' -o -iname '.h' -o -iname '.cc' -o -iname '.hh' ) -print | xargs etags -a

这将不再起作用,因为它还会拾取可能是 csharp、objective c 等的文件...

所以我想要完成的是只让 find 返回名为 cpp 的子目录中的文件。那么我怎样才能找到这样做呢?

谢谢...

【问题讨论】:

    标签: linux find


    【解决方案1】:

    或者更简单(假设在 cpp 目录中没有其他子目录:

    find . -type f -path "*/cpp/*"
    

    这将返回整个相对路径。不过,这可能需要进一步修剪:/

    【讨论】:

      【解决方案2】:

      嵌套的find 可能对你有用

      find . -type d -name "cpp" -exec find {} -type f \;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-07
        • 1970-01-01
        • 1970-01-01
        • 2017-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多