Subject: Re: bug#16922: df --si -h should emit a warning

From: Bernhard Voelker <[email-masked]>
Date: Sun, 02 Mar 2014 18:38:06 +0100

On 03/02/2014 03:33 PM, Pádraig Brady wrote:
> On 03/02/2014 12:33 PM, Mateusz Jończyk wrote:
>> Hello,
>> There should be a warning when running df --si -h because it will display results
>> in blocks of 1024 and not 1000, as one might think (the switch --si displays blocks
>> in a human-readable format when used by itself).
> 
> This is confusing.

Indeed, or not ...

> I think the confusion stems from the option names themselves.
> I.E. I'm not sure you'd want to warn as you might want to support overriding options.
> Consider: alias df='df -h'
> 
> Then you could very well want to `df -H` to override the power from 1024 to 1000.

... because df really honors the last given option (as expected):

  $ src/df -h / | sed 1d
  /dev/sdb2        20G  8.7G   10G  47% /

  $ src/df -H / | sed 1d
  /dev/sdb2        22G  9.3G   11G  47% /

  $ src/df -h -H / | sed 1d
  /dev/sdb2        22G  9.3G   11G  47% /

  $ src/df -H -h / | sed 1d
  /dev/sdb2        20G  8.7G   10G  47% /

> So really the option should be --human-si not just --si.

Well, I'm 80:20 against this. Df(1) just honors the latest option
given - no matter what the name of the option's name is.  Renaming
an option is almost always a "suboptimal" thing for users.
In this case, some might be already used to type "df --human" which
would not be distinguishable from --human-si anymore.

The problem is maybe that "df --help" doesn't explicitly say that -h
is using powers of 1024 no matter what other option was given before.

  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si              likewise, but use powers of 1000 not 1024

However, the info page is quite clear about this:

  `-h'
  `--human-readable'
       Append a size letter to each size, such as `M' for mebibytes.
       Powers of 1024 are used, not 1000; `M' stands for 1,048,576 bytes.
       This option is equivalent to `--block-size=human-readable'.  Use
       the `--si' option if you prefer powers of 1000.

> Also I notice that in GNU df, -h and -H are 1024 and 1000 based respectively,
> whereas on FreeBSD it's the other way around :(

Outch. ;-(

Have a nice day,
Berny