如何递归地将目录复制到另一个目录,并只替换未更改的文件? [英] How can I recursively copy a directory into another and replace only the files that have not changed?

查看:461
本文介绍了如何递归地将目录复制到另一个目录,并只替换未更改的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Fedora中做一个特定的副本。



我有两个文件夹:




  • 'webroot':holding所有网络文件/图像等


  • 'export':包含从我的SVN仓库导出的数千个PHP,




导出目录包含许多与根相同的文件/文件夹,但是根目录包含导出时找不到的其他文件/文件夹。



我想使用以下选项将export的所有内容与我的webroot合并:


  1. 如果导出的版本包含与webroot的版本(live)中的
    不同的代码,则在webroot中覆盖该文件

  2. 保留权限/用户/组的文件,如果它被覆盖(导出
    版本替换实时版本)*注意我想保持webroots权限/所有权,但出口的内容

  3. 没有提示/停止复制
    任何种类(即不详细)

  4. 递归复制 - 显然I
    想复制所有*文件
    文件夹和子文件夹发现在
    export

我对cp做了一些研究 - p>

  cp -pruf ./export / path / to / webroot 


解决方案

这可能,但任何时候 export c $ c> webroot 具有相同的内容,但修改时间不同,您可能会执行不必​​要的复制操作。您可能会从 rsync 获得稍微更聪明的行为:

  rsync  - 此外, rsync     code>可以通过SSH连接将文件从一个主机复制到另一个主机,如果你有需要这样做。此外,它有一个zillion选项,你可以指定调整其行为 - 查看man页面的细节。



编辑:您可能想要离开 -p 选项,以澄清您的意思是什么意思。


I am looking to do a specific copy in Fedora.

I have two folders:

  • 'webroot': holding ALL web files/images etc

  • 'export': folder containing thousands of PHP, CSS, JS documents that are exported from my SVN repo.

The export directory contains many of the same files/folders that the root does, however the root contains additional ones not found in export.

I'd like to merge all of the contents of export with my webroot with the following options:

  1. Overwriting the file in webroot if export's version contains different code than what is inside of webroot's version (live)
  2. Preserve the permissions/users/groups of the file if it is overwritten (the export version replacing the live version) *NOTE I would like the webroots permissions/ownership maintained, but with export's contents
  3. No prompting/stopping of the copy of any kind (ie not verbose)
  4. Recursive copy - obviously I would like to copy all* files folders and subfolders found in export

I've done a bit of research into cp - would this do the job?:

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. You'd probably get slightly smarter behavior from 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. 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.

这篇关于如何递归地将目录复制到另一个目录,并只替换未更改的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆