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.
-h
not working. It is a supported option which causes the output to be in "human readable" (i.e. with unit suffixes and scaled). But it is true that it is ignored when --block-size
is used. This is noted in my answer.
May 28, 2019 at 11:54
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 variableBLOCKSIZE
is set, and the-k
option is not specified, the block counts will be displayed in units of that size block. IfBLOCKSIZE
is not set, and the-k
option is not specified, the block counts will be displayed in512
-byte blocks.
du
is about disk space and/or network transfer time, not about memory footprint.
2 days ago
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