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?

3 Answers 3

  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).
  • 22
    Especially 3) when I pipe the output straight through into sort -n because I'm less interested in quickly seeing the rough size of each directory and more in which subdirectory is taking up disproportionally too much space...
    – Shadur
    Nov 14, 2011 at 8:41
  • 8
    @Shadur Ah but sort takes a -h too! Nov 14, 2011 at 19:52
  • 3
    I think 2 (e.g. for scripting) is the major reason.
    – sml
    Nov 16, 2011 at 1:27
  • @quodlibetor What OS/distro? kubuntu lucid sort does not accept -h and I can see no equivalent.
    – Joe
    Nov 18, 2011 at 23:03
  • 7
    @user23861 sort -h was introduced in GNU coreutils 7.5. Lucid has 7.4, so on Ubuntu you need at least maverick. Nov 19, 2011 at 2:30

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.

  • 2
    Looks like BLOCKSIZE=h might be sufficient. But great tip!
    – Mikel
    Apr 13, 2012 at 1:38
  • 1
    The docs suggest BLOCK_SIZE=human-readable. Also didn't know about support for thousands separators until I read that.
    – Mikel
    Apr 13, 2012 at 5:38
  • Doesn't seem to work on OSX
    – James Lin
    Aug 29, 2019 at 5:07
  • @jameslin: this might be a GNU coreutils specific variable. You could create an alias ...
    – Thor
    Aug 31, 2019 at 17:53

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


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.