[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#28152: Human readable units (-h/--human-readable vs --si) - Wrong pr
From: |
Assaf Gordon |
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 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
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