简体   繁体   English

linux - 在 rsync 之后,当 diff 不显示时,du 会显示大小差异

[英]linux - after rsync, du shows size difference when diff does not

I copied a large folder from NTFS to ext4 using 'rsync' and validating it with 'diff'.我使用“rsync”将一个大文件夹从 NTFS 复制到 ext4,并使用“diff”进行验证。 Just for the shake of curiosity, I also used 'du' command to check if folders had the same size.出于好奇,我还使用了“du”命令来检查文件夹的大小是否相同。 While 'diff' didn't show any difference, 'du' showed that folders had different sizes.虽然 'diff' 没有显示任何差异,但 'du' 显示文件夹具有不同的大小。 I did not encounter any errors while executing the following commands.执行以下命令时我没有遇到任何错误。

rsync --archive --recursive "$src" "$dest" 2>rsync_error.txt

sync

diff --brief --recursive --new-file "$src" "$dest" 1>diff-log.txt 2>diff-error.txt

Then I used 'du' for each folder:然后我为每个文件夹使用了“du”:

du -sb "$src"
du -sb "$dest"
Output:
137197597476
137203512004

1.Why would this happen since there is not any difference? 1.为什么会发生这种情况,因为没有任何区别?

2.Should I be worried about my data or my system? 2.我应该担心我的数据还是我的系统?

EDIT: I also tried 'du -s --apparent-size' and there is still difference.编辑:我也试过 'du -s --apparent-size' 并且仍然存在差异。

du is reporting space including filesystem space, not only file content size. du是报告空间,包括文件系统空间,而不仅仅是文件内容大小。

Also check for hidden files which might not be included in your du .还要检查可能未包含在du隐藏文件。

Greettings Invinciblecache,问候无敌缓存,

Googling around I've found this:谷歌搜索我发现了这个:

As du reports allocation space and not absolute file space, the amount of space on a file system shown by du may vary from that shown by df if files have been deleted but their blocks not yet freed.由于 du 报告分配空间而不是绝对文件空间,如果文件已被删除但其块尚未释放,则 du 显示的文件系统上的空间量可能与 df 显示的空间量不同。 source来源

Not the best source but is a great description of what du is used for.不是最好的来源,但很好地描述了du的用途。

So, I'd rely on diff to check the content of the files, but I would recommend to ignore size difference on filesystem unless it is too high, which is not this the scenario.所以,我会依靠diff来检查文件的内容,但我建议忽略文件系统上的大小差异,除非它太高,这不是这种情况。

Sparses files稀疏文件

Under linux, you could create so-called sparse files .在 linux 下,您可以创建所谓的sparse files They are files where full NULL block don't really exists!它们是真正不存在完整NULL块的文件!

Try this:尝试这个:

$ dd if=/dev/zero count=2048 of=normalfile
2048+0 records in
2048+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0103269 s, 102 MB/s

and

$ dd if=/dev/zero count=0 seek=2048 of=sparsefile
0+0 records in
0+0 records out
0 bytes copied, 0.000182708 s, 0.0 kB/s

then然后

$ ls -l sparsefile normalfile
-rw-r--r-- 1 user  user  1048576 Feb  3 17:53 normalfile
-rw-r--r-- 1 user  user  1048576 Feb  3 17:53 sparsefile

$ du -b sparsefile normalfile
1048576     sparsefile
1048576     normalfile

but

$ du -k sparsefile normalfile
0   sparsefile
1024        normalfile

$ du -h sparsefile normalfile
0   sparsefile
1.0M        normalfile

So long block in sparsefile are not used, they will not be allocated !所以sparsefile中的长块没有被使用,它们不会被分配

$ du -k --apparent-size sparsefile normalfile
1024        sparsefile
1024        normalfile

Then然后

$ diff sparsefile normalfile
echo $?
0

There is virtually no difference between both files!两个文件之间几乎没有区别!

Further更远

$ /sbin/mkfs.ext4 sparsefile 
mke2fs 1.44.5 (15-Dec-2018)
Filesystem too small for a journal
...
Writing superblocks and filesystem accounting information: done

$ ls -l sparsefile normalfile 
-rw-r--r-- 1 user  user  1048576 Feb  3 17:53 normalfile
-rw-r--r-- 1 user  user  1048576 Feb  3 17:59 sparsefile

$ du -k sparsefile 
32  sparsefile

$ diff sparsefile normalfile
Binary files sparsefile and normalfile differ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM