bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#17553: du unit suggestion


From: Pádraig Brady
Subject: bug#17553: du unit suggestion
Date: Thu, 22 May 2014 23:58:07 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

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,
Pádraig.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]