This works:

du -cshm .

But this fails:

du -cshg .

How can I see it in unit of GB?


GNU du has the --block-size option:

du -csh --block-size=1G .

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:

$ 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.


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:

$ du -csh .
32G     .
32G     total
$ du --version | head -1
du (GNU coreutils) 7.4

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.