【问题标题】:how to copy files with subfolders如何复制带有子文件夹的文件
【发布时间】:2021-06-09 13:35:45
【问题描述】:

我有一个文件夹,里面有子文件夹和文件。我想从主文件夹(父)中的所有子文件夹中复制所有 html 文件,并将其放在具有相同文件夹结构的新文件夹(dist)中。 (我使用的是 Mac)

parent

subfolder1 - file1.html, file4.html
subfolder2 - file2.html
subfolder3 - file3.html

预期结果是 dist 文件夹的结构与父文件夹中的相同:

dist 

subfolder1 - file1.html, file4.html
subfolder2 - file2.html
subfolder3 - file3.html

我正在使用这个命令:

cp -R ./parent/templates/**/*.html ./dist/templates

但结果是模板文件夹充满了 .html 文件,但没有复制子文件夹。

dist
file1.html
file2.html
file3.html
file4.html

所以我不知道该怎么做。

【问题讨论】:

    标签: linux shell command-line terminal cp


    【解决方案1】:

    怎么做。

    使用 GNU cp 你可以试试:

    cd ./parent/templates/ &&
    cp -R --parents **/*.html ../../dist/templates
    

    但我建议使用rsync

    【讨论】:

    • 谢谢。最后我选择了更简单的 rsync :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 2013-07-02
    • 2014-07-22
    • 2016-01-30
    相关资源
    最近更新 更多