GNU bug report logs - #28152
Human readable units (-h/--human-readable vs --si) - Wrong prefix and missing unit

Previous Next

Package: coreutils;

Reported by: Michael Weiss <dev.primeos <at> gmail.com>

Date: Sat, 19 Aug 2017 20:25:02 UTC

Severity: wishlist

Tags: wontfix

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Michael Weiss <dev.primeos <at> gmail.com>, 28152 <at> debbugs.gnu.org
Subject: bug#28152: Human readable units (-h/--human-readable vs --si) - Wrong prefix and missing unit
Date: Mon, 21 Aug 2017 17:58:29 -0600
Hello Michael,

On 19/08/17 01:27 PM, Michael Weiss wrote:
> Imho the units used in the output of df, du, ls, etc. with the
> -h/--human-readable option can be very misleading/ambiguous and in the
> case of -h/--human-readable even wrong according to standards.

[...]

> Old:
> 114M	fileA
> 120M	fileA
> New:
> 114MiB	fileA
> 120MB	fileA
[...]
> - http://man7.org/linux/man-pages/man1/numfmt.1.html

You've mentioned numfmt(1), it's worth noting that your
request is exactly what numfmt was designed to do.

The following commands will display df/du/ls output in SI and IEC-I
units, giving the output you wanted:

  ls -l | numfmt --suffix B --field=5 --to=si
  ls -l | numfmt --suffix B --field=5 --to=iec-i

  du | numfmt --format "%-10f" --suffix B --field 1 --to=si
  du | numfmt --format "%-10f" --suffix B --field 1 --to=iec-i

  df | numfmt --suffix B --header --field=2-4 --to=si
  df | numfmt --suffix B --header --field=2-4 --to=iec-i


And these can be rather easily put into a shell function so it'll be
easy to use:

 df_si() { df "$@" | numfmt --suffix B --header --field=2-4 --to=si ; }


Note that numfmt with multiple fields requires coreutils 8.24 or later
(but since you're using 8.27 it should not be a problem).


Hope this helps,
- assaf








This bug report was last modified 6 years and 258 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.