This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
取自手册页:
示例:
Taken from the man page:
Example:
考虑使用
rsync
。根据评论
rsync -a -v src dst
不正确,因为它将更新现有文件。Consider using
rsync
.As per comments
rsync -a -v src dst
is not correct because it will update existing files.就是你想要的。请参阅手册页。
Is what you want. See the man page.
这适用于 RedHat:
更新和不覆盖是不同的。
This will work on RedHat:
Updating and not overwriting is something different.
对于那些发现没有“n”选项的人(比如我在 RedHat 上),您可以使用 cp -u 仅在源比现有源更新时才写入文件(或者有不是现有的)。
[编辑] 正如评论中提到的,这将覆盖旧文件,所以这并不完全是OP想要的。使用 ceving 的答案。
For people that find that don't have an 'n' option (like me on RedHat) you can use
cp -u
to only write the file if the source is newer than the existing one (or there isn't an existing one).[edit] As mentioned in the comments, this will overwrite older files, so isn't exactly what the OP wanted. Use ceving's answer for that.
Alpine linux:以下答案仅适用于单个文件的情况:在 alpine 中
cp -n
不起作用(并且false | cp -i ...
也是)所以我发现在我的情况下工作的解决方案是:在上面的示例中,如果
env.js
文件不存在,那么我们将env.example.js
复制到env.js
。Alpine linux: Below answer is only for case of single file: in alpine
cp -n
not working (andfalse | cp -i ...
too) so solution working in my case that I found is:In above example if
env.js
file not exists then we copyenv.example.js
toenv.js
.某些版本的 cp 没有 --no-clobber 选项。在这种情况下:
Some version of cp do not have the --no-clobber option. In that case:
这对我有用
是的| cp -i 源 目标
This works for me
yes n | cp -i src dest