The difference with and without -h should only be the human readable units, right?
Well apparently no...
$ du -s .
74216696 .
$ du -hs .
35G .
Or maybe I'm mistaken and the result of du -s . isn't in KB?
The difference with and without -h should only be the human readable units, right?
Well apparently no...
$ du -s .
74216696 .
$ du -hs .
35G .
Or maybe I'm mistaken and the result of du -s . isn't in KB?
du without an output format specifier gives disk usage in blocks of 512 bytes, not kilobytes. You can use the option -k to display in kilobytes instead. On OS X (or macOS, or MacOS, or Macos; whichever you like), you can customize the default unit by setting the environment variable BLOCKSIZE (this affects other commands as well).
fdisk, df, and du) work in blocks unless directed otherwise because that is the unit by which they count internally.
– DopeGhoti
Jan 04 '17 at 23:17
du, “block” means 512 bytes. See file block size - difference between stat and ls, Difference between block size and cluster size
– Gilles 'SO- stop being evil'
Jan 04 '17 at 23:44
du.) :)
– Wildcard
Jan 04 '17 at 23:58
The problem is that du returns the size in number of blocks of 512 bytes.
In order to have the size in KB, you can use the -k option that use 1024-byte blocks instead:
$ du -ks .
43351596 .
$ du -khs .
41G .
du --block-size=1024 -s .. Maybe yourBLOCK_SIZEis set to512– Echoes_86 Jan 04 '17 at 18:04-hwas just dividing by 1024 and adding some units – Creak Jan 04 '17 at 21:13echo "74216696*512" | bcoutputs , 37998948352. And yes,-hconverts to human readable form by dividing over and over by 1024. What I got was 35.3887 , which is awfully close to whatdureports. As for size in bytes, just use--block-size=1. On Linux, there's-boption for that, but I'm not familiar with OS Xdu– Sergiy Kolodyazhnyy Jan 05 '17 at 03:01