How do I see du in GB instead of MB in linux?

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.