在使用 --files-from 复制期间使用 rsync 重命名文件?
使用 rsync,如何在使用 --files-from 参数复制时重命名文件?我有大约 190,000 个文件,从源复制到目标时,每个文件都需要重命名。我计划将文本文件中的文件列表传递给 --files-from 参数。
Using rsync, how can I rename files when copying with the --files-from argument? I have about 190,000 files, each of which need to be renamed when copying from source to destination. I plan to have the list of files in a text file to pass to the --files-from argument.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不完全正确...您可以使用 rsync 重命名途中的文件,但前提是一次 rsync 一个文件,并设置 --no-R --no-implied-dirs 选项,然后在目的地路径。
但那时,您可能只想使用其他工具。
例如,这将起作用:
Not entirely true... you CAN rename files enroute with rsync, but only if you rsync one file at a time, and set the --no-R --no-implied-dirs options, then explicitly set the destination name in the destination path.
But at that point, you may just want to use some other tool.
This, for example, would work:
无法使用 rsync 任意重命名文件。 rsync 所能做的就是将文件移动到不同的目录。
您必须在发送方或接收方使用第二个工具来重命名文件。
There is no way to arbitrarily rename files with rsync. All rsync can do is move files to a different directory.
You must use a second tool either on the sending or receiving side to rename the files.
编辑:
刚刚意识到问题要求实际重命名要传输的文件,并且没有尝试解决问题,即使重命名的文件没有更改,也会复制它们(这是我关心的问题)答案如下)。
对于您的问题,您实际上可以使用带有硬链接的方法。不要复制源目录,而是使用 cp --recursive --link
EDIT:
Just realized that the question asks to actually rename the files for the transfer and does not try to solve the issue, that renamed files are copied even when they didn't changed (which was my concern in answer below).
For your question you can actually use an approach with the hard links. Instead of copying your source directory, create a new one as hard links to the same data using
cp --recursive --link <source> <renamed>
(the hard links do not take extra space on your disk) perhaps also with--no-dereference
option to avoid following symbolic links.Then rename the files in the
<renamed>/
directory as you wish, and upload them to the destination.Original answer:
A think this trick using
--hard-links
should do exactly that.Create a hardlink copy of your filenames within the source directory and upload it to the destination. Then rename the files as you please and upload the changes -- since the hardlinks are preserved, no data are actually transffered. Finally you can delete the directory with the hardlinks in your source, which will also vanish from the destination if you use
--delete
option in thersync
.To illustrate it with a code look at the following output: