[英]How can I recursively copy a directory into another and replace only the files that have not changed?
I am looking to do a specific copy in Fedora. 我希望在Fedora中做一个特定的副本。
I have two folders: 我有两个文件夹:
'webroot': holding ALL web files/images etc 'webroot':持有所有网络文件/图像等
'export': folder containing thousands of PHP, CSS, JS documents that are exported from my SVN repo. 'export':包含从我的SVN仓库导出的数千个PHP,CSS,JS文档的文件夹。
The export directory contains many of the same files/folders that the root does, however the root contains additional ones not found in export. 导出目录包含许多与root相同的文件/文件夹,但是根目录包含导出中找不到的其他文件/文件夹。
I'd like to merge all of the contents of export with my webroot with the following options: 我想通过以下选项将导出的所有内容与我的webroot合并:
I've done a bit of research into cp - would this do the job?: 我对cp进行了一些研究 - 这可以做到这一点吗?:
cp -pruf ./export /path/to/webroot
It might, but any time the corresponding files in export
and webroot
have the same content but different modification times, you'd wind up performing an unnecessary copy operation. 它可能,但是只要
export
和webroot
的相应文件具有相同的内容但修改时间不同,您最终会执行不必要的复制操作。 You'd probably get slightly smarter behavior from rsync
: 您可能从
rsync
获得稍微聪明的行为:
rsync -pr ./export /path/to/webroot
Besides, rsync
can copy files from one host to another over an SSH connection, if you ever have a need to do that. 此外,如果您需要这样做,
rsync
可以通过SSH连接将文件从一个主机复制到另一个主机。 Plus, it has a zillion options you can specify to tweak its behavior - look in the man page for details. 此外,它还有许多选项可供您调整以调整其行为 - 请查看手册页以获取详细信息。
EDIT : with respect to your clarification about what you mean by preserving permissions: you'd probably want to leave off the -p
option. 编辑 :关于你通过保留权限澄清你的意思:你可能想要
-p
选项。
So looks like you got all the correct args to cp 所以看起来你得到了所有正确的args到cp
Sounds like a job for cpio
(and hence, probably, GNU tar can do it too): 听起来像
cpio
的工作(因此,GNU tar可能也可以这样做):
cd export
find . -print | cpio -pvdm /path/to/webroot
If you need owners preserved, you have to do it as root, of course. 如果你需要保留所有者,你当然必须以root身份完成。 The
-p
option is 'pass mode', meaning copy between locations; -p
选项是“传递模式”,意味着在位置之间复制; -v
is verbose (but not interactive; there's a difference); -v
是冗长的(但不是交互式的;有区别的); -d
means create directories as necessary; -d
表示根据需要创建目录; -m
means preserve modification time. -m
表示保留修改时间。 By default, without the -u
option, cpio
won't overwrite files in the target area that are newer than the one from the source area. 默认情况下,如果没有
-u
选项, cpio
将不会覆盖目标区域中比源区域中的文件更新的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.