有时我有两棵树,它们曾经具有相同的内容,但已经不同步了(因为我移动了磁盘或其他什么)。一个很好的例子是我从 Fedora 镜像上游包的树。
我想通过将所有文件从 tree1 移动到 tree2 来再次合并这两棵树。
通常我这样做:
rsync -arv tree1/* tree2
Run Code Online (Sandbox Code Playgroud)
然后删除tree1。
但是,这需要大量的时间和磁盘空间,并且能够更容易地做到:
mv -r tree1/* tree2
Run Code Online (Sandbox Code Playgroud)
换句话说,递归移动。它会更快,因为首先它甚至不会复制,只需移动 inode,其次我不需要最后删除。
这存在吗?
作为测试用例,请考虑以下命令序列:
$ mkdir -p a/b
$ touch a/b/c1
$ rsync -arv a/ a2
sending incremental file list
created directory
./
b/
b/c1
b/c2
sent 173 bytes received 57 bytes 460.00 bytes/sec
total size is 0 speedup is 0.00
$ touch a/b/c2
Run Code Online (Sandbox Code Playgroud)
现在什么命令可以将 a/b/c2 移动到 a2/b/c2 然后删除 a 子树(因为其中的所有内容都已经在目标树中)?
根据 gnu 的 mv(1) 联机帮助页mv
:
-u, --update
move only when the SOURCE file is newer than the destination
file or when the destination file is missing