关于du和du -h
来源:3-6 目录大小

乃好
2020-02-29
老师你好,在9:35的时候你展示了du命令,并且说单位是字节
这里是83948个字节,也就是83948Bytes
然后又使用了du -h命令,显示的是82M
,82个MB,可是我觉得换算不太对呀
到底是哪里出了问题?
写回答
2回答
-
不好意思,视频中我没有很严谨地解释,是有不妥之处的。
du 命令如果你不带任何参数来运行,会显示当前目录的磁盘占用,以 block(块)为单位。
如果你用
man du
来查看 du 命令的手册,可以看到有这么一段关于环境变量的:
ENVIRONMENT BLOCKSIZE If the environment variable BLOCKSIZE is set, and the -k option is not specified, the block counts will be displayed in units of that size block. If BLOCKSIZE is not set, and the -k option is not specified, the block counts will be displayed in 512-byte blocks.
就是说如果你没有设置 BLOCKSIZE(表示“块的大小”)这个环境变量并且也没有用 -k 参数(-k 参数的作用手册中也有,是“Display block counts in 1024-byte (1-Kbyte) blocks”,就是说以块大小为 1024 Byte,也就是 1024 字节,也就是每个块大小是 1 KB 这样来显示),那么就会以块大小为 512 Byte(也就是 0.5 KB)来显示。
所以,如果我用 du 命令和 du -h 命令得到的数值是不一样的,前者一般正好是后者的两倍。例如:
10 -
cn_five
2020-03-08
如果你不在du参数 --block-size= 此处设置,或者环境变量里有设置,Otherwise, units default to 1024 bytes 。默认1024字节。83948Bytes/1024=81.98046875M,差不多82M。
00
相似问题