macos 跳过存在的文件时复制文件 - Unix
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8394356/
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 files while skipping over files that exist - Unix
提问by switz
I'd like to take a large folder (~100GB) and copy it over to another folder. I'd like it to skip any files that exist (not folders) so if /music/index.html
does not exist it would still copy even though the /music
directory already exists.
我想要一个大文件夹(~100GB)并将其复制到另一个文件夹。我希望它跳过任何存在的文件(不是文件夹),所以如果/music/index.html
不存在它仍然会复制,即使/music
目录已经存在。
I found this, but my shell is saying -u
is not a valid argument.
我发现了这个,但我的外壳说-u
这不是一个有效的论点。
I don't know how rsync
works, so please let me know if that's a better solution.
我不知道如何rsync
工作,所以请让我知道这是否是更好的解决方案。
Thanks.
谢谢。
回答by Kerrek SB
Always use rsync
for copying files, because It Is Great.
总是rsync
用于复制文件,因为它很棒。
To ignore existing files:
要忽略现有文件:
rsync --ignore-existing --recursive /src /dst
Do read the manualand search around for many, many great examples. Especially the combination with ssh makes rsync
a great tool for slow and unreliable connections on account of its --partial
option. Add --verbose
to see which files are being copied. Be sure to check out the plethora of options concerning preservation of permissions, users and timestamps, too.
一定要阅读手册并搜索很多很多很好的例子。尤其是与 ssh 的结合,rsync
由于它的--partial
选项,它成为处理缓慢和不可靠连接的绝佳工具。添加--verbose
以查看正在复制哪些文件。请务必查看有关保留权限、用户和时间戳的大量选项。
回答by sarnold
rsync(1)
absolutely shines when the source and destination are on two different computers. It is still the better tool to use when the source and destination are on the same computer.
rsync(1)
当源和目标位于两台不同的计算机上时,绝对会发光。当源和目标在同一台计算机上时,它仍然是更好的工具。
A simpleuse would look like:
一个简单的用法如下所示:
rsync -av /path/to/source /path/to/destination
If you're confident that any files that exist in both locations are identical, then use the --ignore-existing
option:
如果您确信两个位置中存在的任何文件都相同,请使用以下--ignore-existing
选项:
rsync -av --ignore-existing /path/to/source /path/to/destination
Just for completeness, when I use rsync(1)
to make a backup on a remote system, the command I most prefer is:
为了完整起见,当我用来rsync(1)
在远程系统上进行备份时,我最喜欢的命令是:
rsync -avz -P /path/to/source hostname:/path/to/destination
The -z
asks for compression (I wouldn't bother locally, but over a slower network link it can make a big difference) and the -P
asks for --partial
and --progress
-- which will re-use partialfile transfers if it must be restarted, and will show a handy progress bar indicator.
该-z
请求压缩(我不会理会本地,但在较慢的网络链接它可以使一个很大的区别),并且-P
询问--partial
和--progress
-这将重新使用部分文件传输,如果它必须重新启动,并显示一个方便的进度条指示器。