As sajb noted, omitting the block size argument will automatically scale the output (and display the unit). Using any block size argument displays the number but omits the unit.
-h "Human-readable" output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte.
-k Display block counts in 1024-byte (1-Kbyte) blocks.
-m Display block counts in 1,048,576-byte (1-Mbyte) blocks.
-g Display block counts in 1,073,741,824-byte (1-Gbyte) blocks.
Here is how the various options work given a 1,234,567 KB file:
$ mkfile -n 1234567k file.txt
$ du file.txt
2469136 file.txt
$ du -k file.txt
1234568 file.txt
$ du -m file.txt
1206 file.txt
$ du -g file.txt
2 file.txt
$ du -h file.txt
1.2G file.txt
Also worth noting, you can configure implicit behaviour though the BLOCKSIZE environment variable:
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.
GNU
du
has the--block-size
option:As sajb noted, omitting the block size argument will automatically scale the output (and display the unit). Using any block size argument displays the number but omits the unit.
For convenience, here's reference for macOS:
-h
"Human-readable" output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte.-k
Display block counts in 1024-byte (1-Kbyte) blocks.-m
Display block counts in 1,048,576-byte (1-Mbyte) blocks.-g
Display block counts in 1,073,741,824-byte (1-Gbyte) blocks.Here is how the various options work given a
1,234,567 KB
file:Also worth noting, you can configure implicit behaviour though the
BLOCKSIZE
environment variable:Use
du -B1073741824
but beware, it gives the result in integer-units only, and won't be meaningful with-h
In addition to the previous answers, it also seems to differ between different coreutils versions (or locale?), since on my host I get: