我对Linux中命令'du'的输出感到困惑


21

我创建了一个名为file.o的文件,我想检查file.o文件的大小。

du -h file.o ====> 4.0K

du -b file.o ====> 1120

根据du -b file.o,我知道file.o的大小为1120bytes。但是为什么du -h file.o输出4.0K(表示4 * 1024字节)?

Answers:


33

该文件较小,但是在磁盘上占用了整个4.0K块(一个块中只能有一个文件)。如果其字节大小为(例如)5678字节,则它将占用两个4.0K块,即8.0K。

du -b 打印以字节为单位的大小,覆盖默认的块大小。


10

为了增加eumiro的答案,每个文件系统/分区的块大小可以不同。

您可以使用tune2fs -l /dev/<disk> | grep '^Block size'或查找文件系统的块大小stat -c "%o" <file on the disk>

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.