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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:40:35  来源:igfitidea点击:

Copy files while skipping over files that exist - Unix

macosshellunixterminal

提问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.htmldoes not exist it would still copy even though the /musicdirectory already exists.

我想要一个大文件夹(~100GB)并将其复制到另一个文件夹。我希望它跳过任何存在的文件(不是文件夹),所以如果/music/index.html不存在它仍然会复制,即使/music目录已经存在。

I found this, but my shell is saying -uis not a valid argument.

我发现了这个,但我的外壳说-u这不是一个有效的论点。

I don't know how rsyncworks, so please let me know if that's a better solution.

我不知道如何rsync工作,所以请让我知道这是否是更好的解决方案。

Thanks.

谢谢。

回答by Kerrek SB

Always use rsyncfor 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 rsynca great tool for slow and unreliable connections on account of its --partialoption. Add --verboseto 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-existingoption:

如果您确信两个位置中存在的任何文件都相同,请使用以下--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 -zasks for compression (I wouldn't bother locally, but over a slower network link it can make a big difference) and the -Pasks for --partialand --progress-- which will re-use partialfile transfers if it must be restarted, and will show a handy progress bar indicator.

-z请求压缩(我不会理会本地,但在较慢的网络链接它可以使一个很大的区别),并且-P询问--partial--progress-这将重新使用部分文件传输,如果它必须重新启动,并显示一个方便的进度条指示器。