为什么`du`的输出和`du -b`差不多 [英] why is the output of `du` often so different from `du -b`

查看:280
本文介绍了为什么`du`的输出和`du -b`差不多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 du 的输出经常和 du -b 不一样? -b - apparent-size --block-size = 1 的缩写。只使用 - apparent-size 大部分时间都给出了相同的结果,但是 - block-size = 1 似乎是伎俩。我想知道输出是否正确,哪个数字是我想要的? (即实际的文件大小,如果复制到另一个存储设备)。

解决方案

表观大小是你的应用程序认为是在文件中的字节。如果您决定通过FTP或HTTP发送文件,则是通过网络传输的数据量(不包括协议标题)。这也是 cat theFile |的结果wc -c ,以及使用 mmap 加载整个文件时占用的地址空间量。 b
$ b

磁盘使用量是由于文件占用该空间而无法用于其他内容的空间量。



在大多数情况下,表观大小小于磁盘使用量,因为磁盘使用量是文件最后(部分)块的全部大小,而表观大小只计数最后一个块中的数据。然而,当你有一个稀疏的文件时,表面大小会更大(当你寻找文件末尾的某处时会创建稀疏文件,然后在那里写一些东西 - 操作系统不会打扰大量的用零填充的块 - - 它只为您决定写入的文件部分创建一个块)。


why is the output of du often so different from du -b? -b is shorthand for --apparent-size --block-size=1. only using --apparent-size gives me the same result most of the time, but --block-size=1 seems to do the trick. i wonder if the output is then correct even, and which numbers are the ones i want? (i.e. actual filesize, if copied to another storage device)

解决方案

Apparent size is the number of bytes your applications think are in the file. It's the amount of data that would be transferred over the network (not counting protocol headers) if you decided to send the file over FTP or HTTP. It's also the result of cat theFile | wc -c, and the amount of address space that the file would take up if you loaded the whole thing using mmap.

Disk usage is the amount of space that can't be used for something else because your file is occupying that space.

In most cases, the apparent size is smaller than the disk usage because the disk usage counts the full size of the last (partial) block of the file, and apparent size only counts the data that's in that last block. However, apparent size is larger when you have a sparse file (sparse files are created when you seek somewhere past the end of the file, and then write something there -- the OS doesn't bother to create lots of blocks filled with zeros -- it only creates a block for the part of the file you decided to write to).

这篇关于为什么`du`的输出和`du -b`差不多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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