简体   繁体   English

如何复制带有子文件夹的文件

[英]how to copy files with subfolders

I have folder with subfolders and files inside.我有一个文件夹,里面有子文件夹和文件。 I want to copy all html files from all subfolders in main folder (parent) and have it in new folder (dist) with the same folder structure.我想从主文件夹(父)中的所有子文件夹中复制所有 html 文件,并将其放在具有相同文件夹结构的新文件夹(dist)中。 (I am using Mac) (我使用的是 Mac)

parent

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

Expected result is dist folder with structure the same as in parent folder:预期结果是结构与父文件夹相同的 dist 文件夹:

dist 

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

I am using this command:我正在使用这个命令:

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

But the result is templates folder filled up with.html files but no subfolders copied.但结果是模板文件夹充满了.html 文件,但没有复制子文件夹。

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

So I am not sure how to do it.所以我不知道该怎么做。

how to do it.怎么做。

With GNU cp you could try:使用 GNU cp你可以尝试:

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

But I would recommend to use rsync .但我建议使用rsync

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从特定子文件夹复制文件 - Copy files from specific subfolders 如何复制已选择文件的文件夹和子文件夹 - How to copy folders and subfolders which have selected files 如何以文件夹及其子文件夹的形式递归复制文件作为符号链接 - How to recursively copy files under a folder and its subfolders as symbolic links 如何创建子文件夹和移动文件 - how to create subfolders and move files 如何在Linux中将多个子文件夹压缩成单独的文件? - How to compress multiple subfolders into separate files in linux? 如何对子文件夹中的文件使用 stat 命令? - How to use the stat command for files that are in subfolders? 如何监控包含所有子文件夹和文件的文件夹? - How to monitor a folder with all subfolders and files inside? 复制子文件夹,ZIP和RAR的所有文件,而不会覆盖目标文件夹中具有相同名称的文件 - Copy all files from subfolders, ZIP's and RAR's, without overwriting files with same name in destination folders 如何使用linux命令将jpg文件转换为png文件? + 难度 = 子文件夹 - How to convert jpg files into png files with linux command? + Difficulty = Subfolders Linux - 将文件(不是子文件夹)从源复制到目标,同时覆盖/删除目标文件夹中的初始内容 - Linux - Copy the files (not subfolders) from origin to destination while overwriting/deleting the initial contents in the destination folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM