2

When i view the man page of ls on Yosemite I read the following:

-h      When used with the -l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to
        reduce the number of digits to three or less using base 2 for sizes.

But shouldn't that read base 10?

When I use the command ls -lh I see a files that is exactly 1000 bytes appearing as 1.0K (1 kilobyte). A file that is 999 bytes appears as 999B.

Isn't that base 10? Is that manual wrong or am I missing something?

Youri Thielen
  • 440
  • 4
  • 10
  • “see a files that is exactly 1000 bytes appearing as 1.0K” No, the number of significant digits is such that 1.0K could be `ls`'s way of telling you that the file is slightly less than 1024 bytes. You should test what happens for 1022, 1024 and 1026 bytes. – Pascal Cuoq Oct 23 '14 at 12:12
  • 1022, 1024 and 1026 all show 1.0K – Youri Thielen Oct 23 '14 at 12:50
  • So I guess it is base 2 but rounded? – Youri Thielen Oct 23 '14 at 12:54
  • So there is no reason yet to suspect that your `ls` does not correctly use binary units (more properly called “kebibytes” and “mebibytes”) for `-h`. It could only be rounding the results to 2-3 significant digits, as you say. – Pascal Cuoq Oct 23 '14 at 12:54
  • This is even more strange output: `dd if=/dev/zero of=output.dat bs=999 count=1025` `ls -lh` `-rw-r--r-- 1 kecso 285597778 1000 May 11 21:34 output.dat` 1000 what? :) `ls -l` `-rw-r--r-- 1 kecso 285597778 1023975 May 11 21:34 output.dat` – kecso May 12 '15 at 04:39

0 Answers0