Rsync使平面复制 [英] Rsync make flat copy
问题描述
我想写一个脚本,将一个dir(含子目录)的所有文件复制到另一个目录的根目录。
I'm trying to write a script that copy all the files of one dir (with subdirs) to the root of another dir.
文件结构:
/
pic.JPG
PIC5.JPG
FOLDER
pic2.JPG
pic3.JPG
FOLDER2
pic4.JPG
我想从该目录的所有.JPG文件,并将其复制到另一个目的地。但我不想要目录结构,只是文件。
I want all the .JPG files from that directory and copy them over to another destination. But I don't want the directory structure, just the files.
这是我得到的:
"sudo rsync -aq --include '*/' --include '*.JPG' --exclude '*\' /source/picturesRoot/ /destination/flatView/
但它也复制目录:
我在stackoverflow上找到这个链接:
rsync:递归同步所有文件,而忽略目录结构
我查看了解决方案,没有看到与我的命令有很多区别,除了路径中的*和。我尝试了它,但它没有工作。
I looked at the solution and didn't see much difference with my command, apart from the * and . in the path. I tried it but it didn't work.
我希望有人能帮助我,谢谢。
I hope somebody can help me, thanks.
推荐答案
这个答案不能为你工作,因为你的图片不在同一级别的目录中。 rsync
没有选项可以跳过目录结构的创建。您提供的链接,它的工作,因为用户明确选择源文件与 *
。
This answer cannot work for you because your pictures are not at the same level in directories. There is no option in rsync
to skip the creation of directory structure. In the link you gave, it's working because the user explicitly select source files with *
.
find
和 rsync
。 查找
会找到文件,并且 rsync
复制。
You can try something with find
and rsync
. Find
will find files and rsync
copy them.
这里是一个解决方案:
find /source/picturesRoot -type f -name "*.JPG" -exec rsync -a {} /destination/flatView/ \;
注意,如果两个文件具有相同的名称,则只有一个文件位于目标目录中。
Be careful, if two files have the same name just one will be in destination directory.
这篇关于Rsync使平面复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!