du 命令显示 1t 没问题吧?

2022-04-17 08:27:06 +08:00
 azev
有个快存满了的 1T 移动硬盘
du -h 的时候显示 921.2G 可是 du 的时候显示 1931852288
怎么数也对不上啊?咋回事?
1250 次点击
所在节点    问与答
6 条回复
kokutou
2022-04-17 08:56:17 +08:00
有硬链接?
alect
2022-04-17 09:23:05 +08:00
df -h
azev
2022-04-17 09:39:47 +08:00
@alect

df -h
/dev/sda1 931.5G 921.3G 10.2G 99% /var/media/onet

df
/dev/sda1 976761540 966092840 10668700 99% /var/media/onet
iBugOne
2022-04-17 12:59:00 +08:00
看 man ,du 的默认输出单位是 sector ,也就是 512 字节,1931852288 乘以 512 字节的结果没啥问题
azev
2022-04-17 14:27:42 +08:00
@iBugOne 这个默认貌似是不同发行版不一样? Google 'du 默认输出单位' 不少提及是 kb 为默认单位
ynyounuo
2022-04-18 07:11:13 +08:00
@azev Posix compliant 的单位是 512 bytes ,所以 GNU du 设置了 POSIXLY_CORRECT=1 的话就会用 512 bytes ,BSD du 也一般是 default to 512 bytes

> The use of 512-byte units is historical practice and maintains compatibility with ls and other
utilities in this volume of POSIX.1-2017. This does not mandate that the file system itself be
based on 512-byte blocks.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/du.html#RATIONALE

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/847430

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX