bash 将嵌套文件夹内容递归复制到一个文件夹(终端)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1936187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy nested folders contents to one folder recursively (terminal)
提问by Wolfr
I have a Wordpress upload folder that is structured using subfolders for months.
我有一个 Wordpress 上传文件夹,它使用子文件夹构建了几个月。
wolfr2:uploads wolfr$ tree .
.
|-- 2007
| |-- 08
| | |-- beautifulkatamari.jpg
| | |-- beautifulkatamari.thumbnail.jpg
| | |-- beetle.jpg
| | |-- beetle.thumbnail.jpg
How do I use terminal to copy all the images recursively into another folder? I can't seem to wildcard folders like you can wildcard filenames. (e.g. *.jpg or *) (I'm on Mac OSX)
如何使用终端将所有图像递归复制到另一个文件夹中?我似乎无法像通配符文件名那样通配文件夹。(例如 *.jpg 或 *)(我在 Mac OSX 上)
cp -R ./*.jpg .
?
?
回答by Richard Pennington
This will copy all *.jpg files from the current folder to a new folder and preserve the directory structure.
这会将当前文件夹中的所有 *.jpg 文件复制到新文件夹并保留目录结构。
tar cvfp `find . -name "*.jpg"` | (cd <newfolder>; tar xfp -)
To copy without preserving the directory structure:
要在不保留目录结构的情况下进行复制:
cp `find . -name "*.jpg"` <newfolder>
回答by Lucas Jones
Off the top of my head:
在我的头顶:
find . -type f -name \*.jpg -exec cp \{\} $TARGETFOLDER \;
If that doesn't work, comment and I'll try again, but find
is definitely the way to go.
如果这不起作用,请发表评论,我会再试一次,但find
绝对是要走的路。