cp 命令,忽略未更改的文件

Ben*_*ard 11 linux terminal cp ignore

有没有办法做一个cp但忽略目标中可能已经存在的任何文件,这些文件不比源文件中的那些文件更旧。

基本上我想将一个磁盘的内容复制到另一个磁盘,然后再次运行复制,但只更新新文件或已在源端更新的文件。

谢谢

Uta*_*ead 18

用这个:

rsync -a /source /destination
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用其他一些标志(如-v或 )获取更多详细信息--progress

  • 我想补充一点,您也可以通过网络使用“rsync”。使用“ssh”尤其容易做到这一点。对于源*或*目的地,在其前面加上`user@host:`,它就会这样做。这将替代“scp” (2认同)

ste*_*tew 10

cp联机帮助页:

   -u, --update
          copy only when the SOURCE file is newer than the destination file or when  the
          destination file is missing
Run Code Online (Sandbox Code Playgroud)


Sve*_*ven 7

使用rsync,问题解决。

rsync -av /srcdir /tgtdir
Run Code Online (Sandbox Code Playgroud)