【问题标题】:How to recursively copy specific file and keep name of parent directory如何递归复制特定文件并保留父目录的名称
【发布时间】:2017-04-01 00:51:05
【问题描述】:

我有多个不同名称的文件夹:folderA、FolderB 等。 每个文件夹中都有多个文件:fileA、fileB、fileC 等。

我想搜索所有这些文件夹并仅将特定文件复制到新位置但具有相同的父文件夹名称:例如我要生成:

new_location/folderA/fileA
new_location/folderA/fileC
new_location/folderB/fileA
new_location/folderB/fileC

任何人都可以建议可以完成此任务的 unix 命令吗?

谢谢

罗伯

【问题讨论】:

    标签: unix search copy-paste


    【解决方案1】:

    这在一定程度上取决于您如何指定特定文件。

    找到文件夹A 文件夹B 文件夹C -type d -exec mkdir -p new_location/{} \; will 应该创建正确的子目录

    find folderA folderB folderB -name somepattern -exec cp {} new_location/{} \;

    可能需要也可能不需要担心额外的“/”,具体取决于目录名称等

    【讨论】:

    • 你可以使用cp --parent来避免使用find ... -exec mkdir创建目录
    • 感谢您的提示。更好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    • 2010-09-18
    • 1970-01-01
    • 2010-12-11
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多