56

Several command line tools use the -h or --human-readable option to print file size in a human readable format (i.e., 36G vs 37550836).

  • Why is this option needed and not the default?
  • Aren't these tools mainly for output to humans?
DQdlM
  • 1,543

3 Answers3

77
  1. Because they didn't exist originally, and the default behavior is backwards compatible. Also, because they don't exist on all unix variants, and the default behavior is compatible with other unix variants.
  2. For many tools, because they are intended to be parseable by other tools. This is rarely the case for ls, but parsing the output of du or df is relatively common. (Mind, for df, you should use df -P when parsing.)
  3. Because some humans prefer the 37550836 format, because when you see a bunch of such numbers, their relative size is visually clear (number of digits).
15

Note that if you set BLOCKSIZE=human-readable in your environment, this will be the default, at least for the commands from GNU coreutils, i.e. if you're using bash put:

export BLOCKSIZE=human-readable

in your $HOME/.bashrc file.

Thor
  • 17,182
6

Beside what Gilles said:

When these tools where invented hdd was very small, compared with today. You didn't need help to read a number like 400000.

And if you don't like it, use the alias system. In your home directory,

edit ~/.bashrc 

and insert, for example:

alias df='df -h'
alias du='du -h'

Note that in contrast to many other languages, you aren't allowed to have a blank before or behind the assignment operator (equal sign).

user unknown
  • 10,482