【问题标题】:How can I find all files in any matching sub folder groups and copy them to a new directory?如何在任何匹配的子文件夹组中找到所有文件并将它们复制到新目录?
【发布时间】:2021-04-25 06:11:43
【问题描述】:

我有一个由多个子项目构成的项目。作为该项目的一部分,我有一些在快照 UI 测试失败时生成的失败差异。

当前已添加到原始快照旁边的文件夹中。

我希望能够运行测试套件并将任何故障快照复制到一个位置 - 这将在 CI 期间发生,并使我能够将它们存储为工件。

结构有点像;

Project/
    Framework A/
        snapshots/
            failures/
                failure_a_img_1.png
                failure_a_img_2.png
    Framework B/
        snapshots/
            failures/
                failure_b_img_1.png
                failure_b_img_2.png            
                failure_b_img_3.png            
.........
    Framework Z/
        snapshots/
            failures/
                failure_z_img_1.png
                failure_z_img_2.png            

我基本上希望能够搜索整个 Project 文件夹并复制与 snapshots/failures 匹配的文件夹组内的任何文件

如果我在终端中运行echo **/*snapshots/failures/*,我会看到所有文件/位置。 我尝试使用

构造一个命令
find . -iname "**/*snapshots/failures/*.png" -type f -exec cp {} ~/desktop \;

但没有输出/没有复制任何内容。

如有任何帮助,我将不胜感激。

【问题讨论】:

    标签: bash shell terminal


    【解决方案1】:

    您应该将目录 glob 传递给 find,并将文件名传递给 -iname

    find **/*snapshots/failures -iname "*.png" -type f -exec cp {} ~/desktop \; 
    

    【讨论】:

      【解决方案2】:

      为此使用-pathipath 选项。这两个选项再次匹配给定的 glob 模式路径名:

      find . -ipath "*/snapshots/failures/*" -type f -exec cp {} ~/desktop \;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-07
        • 2021-02-16
        • 2022-10-15
        • 1970-01-01
        • 2021-07-06
        • 1970-01-01
        相关资源
        最近更新 更多