GNU bug report logs -
#17553
du unit suggestion
Previous Next
Reported by: Reuben Thomas <rrt <at> sc3d.org>
Date: Thu, 22 May 2014 19:48:02 UTC
Severity: normal
Tags: notabug
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On 22 May 2014 23:58, Pádraig Brady <P <at> draigbrady.com> wrote:
> On 05/22/2014 08:47 PM, Reuben Thomas wrote:
> > It would be helpful to this addle-pated individual if du would output the
> > same units as it accepts as SIZE inputs, so that one could more readily
> > tell whether one was getting 1000-based or 1024-based units.
> >
> > For additional clarity, it would help if for output the suffix were "B"
> as
> > at present for 1000-based units and "iB" for 1024-based (and
> > correspondingly it would be nice if "iB" suffixed units were accepted as
> > input. As far as input goes, it's backwards-compatible; it's not for
> output
> > if other programs are trying to parse the human-readable output, but
> maybe
> > that's not a problem.
>
> Yes this is not ideal, but it half does what you want:
> With this file:
>
> $ truncate -s 1MiB file.in
>
> We can output the appropriate suffixes for a _particular_ power.
>
> $ du --apparent-size -BKiB file.in
> 1024KiB file.in
> $ du --apparent-size -BKB file.in
> 1049kB file.in
>
> However if we want to auto scale the number with -h we lose the suffix,
> and have an ambiguity:
>
> $ du --apparent-size -h file.in
> 1.0M file.in
> $ du --apparent-size -h --si file.in
> 1.1M file.in
>
> If you wanted to get auto scaling with suffixes you could use
> the new numfmt utility which has various number formatting options.
> The advantage of that is it concentrates the myriad of number formatting
> options in a single location, and allows processing of numbers before
> final presentation by numfmt. For example:
>
> $ du -B1 . | sort -k1,1n | numfmt --to=iec-i | tail -n5
> 104Mi ./gnulib/.git/objects/pack
> 216Mi ./gnulib/.git/objects
> 218Mi ./gnulib/.git
> 274Mi ./gnulib
> 479Mi .
>
Thanks for clarifying what is possible. Currently du's behaviour is more
inconsistent than I'd realised. I see that if one wanted more complicated
units it would make sense to use an external utility, but here I'd just
like -h's output to be consistent with --apparent-size's output.
It seems that -iB suffixed units are already accepted as input, which was
my second request, but not documented in the man page. I'd like to fix
this, but without duplicating information. What's best: to add a phrase
saying that SI units are accepted and/or to make a cross-reference to the
relevant node of the info manual?
--
http://rrt.sc3d.org
[Message part 2 (text/html, inline)]
This bug report was last modified 1 year and 28 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.