900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > linux两个文件夹内容同步 如何使用命令行工具同步两个文件夹?

linux两个文件夹内容同步 如何使用命令行工具同步两个文件夹?

时间:2021-12-13 04:01:07

相关推荐

linux两个文件夹内容同步 如何使用命令行工具同步两个文件夹?

TuxForLife的答案很好,但我强烈建议您-c在本地同步时使用。您可以辩解说,为远程同步这样做不值得花费时间/网络代价,但是对于本地文件来说完全值得,因为速度是如此之快。

-c, --checksum

This forces the sender to checksum every regular file using a 128-bit MD4

checksum. It does this during the initial file-system scan as it builds

the list of all available files. The receiver then checksums its version

of each file (if it exists and it has the same size as its sender-side

counterpart) in order to decide which files need to be updated: files with

either a changed size or a changed checksum are selected for transfer.

Since this whole-file checksumming of all files on both sides of the con-

nection occurs in addition to the automatic checksum verifications that

occur during a file's transfer, this option can be quite slow.

Note that rsync always verifies that each transferred file was correctly

reconstructed on the receiving side by checking its whole-file checksum,

but that automatic after-the-transfer verification has nothing to do with

this option's before-the-transfer "Does this file need to be updated?"

check.

这显示了具有相同大小和时间戳的方法会使您失败。

设置

$ cd /tmp

$ mkdir -p {A,b}/1/2/{3,4}

$ echo "\___________from A" | \

tee A/1/2/x | tee A/1/2/3/y | tee A/1/2/4/z | \

tr A b | \

tee b/1/2/x | tee b/1/2/3/y | tee b/1/2/4/z | \

tee b/1/2/x0 | tee b/1/2/3/y0 > b/1/2/4/z0

$ find A b -type f | xargs -I% sh -c "echo %; cat %;"

A/1/2/3/y

\___________from A

A/1/2/4/z

\___________from A

A/1/2/x

\___________from A

b/1/2/3/y

\___________from b

b/1/2/3/y0

\___________from b

b/1/2/4/z

\___________from b

b/1/2/4/z0

\___________from b

b/1/2/x

\___________from b

b/1/2/x0

\___________from b

rsync不复制任何内容,因为文件都具有相同的大小和时间戳

$ rsync -avu A/ b

building file list ... done

sent 138 bytes received 20 bytes 316.00 bytes/sec

total size is 57 speedup is 0.36

$ find A b -type f | xargs -I% sh -c "echo %; cat %;"

A/1/2/3/y

\___________from A

A/1/2/4/z

\___________from A

A/1/2/x

\___________from A

b/1/2/3/y

\___________from b

b/1/2/3/y0

\___________from b

b/1/2/4/z

\___________from b

b/1/2/4/z0

\___________from b

b/1/2/x

\___________from b

b/1/2/x0

\___________from b

正确工作的rsync,因为它比较校验和

$ rsync -cavu A/ b

building file list ... done

1/2/x

1/2/3/y

1/2/4/z

sent 381 bytes received 86 bytes 934.00 bytes/sec

total size is 57 speedup is 0.12

$ find A b -type f | xargs -I% sh -c "echo %; cat %;"

A/1/2/3/y

\___________from A

A/1/2/4/z

\___________from A

A/1/2/x

\___________from A

b/1/2/3/y

\___________from A

b/1/2/3/y0

\___________from b

b/1/2/4/z

\___________from A

b/1/2/4/z0

\___________from b

b/1/2/x

\___________from A

b/1/2/x0

\___________from b

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。