Subject: Re: bug#20936: suggestion for a 'wart-ish' extension off of 'sort'

From: Assaf Gordon <[email-masked]>
Date: Tue, 30 Jun 2015 13:05:38 -0400

Hello,

On 06/30/2015 03:28 AM, Linda Walsh wrote:
> I admit the ability to show a summary line might not bethe first
> thing you'd think a pure-sorting utility might do, but it would be
> awfully handy if sort had a 'Numeric sum' option ("-N" -- preferred
> '-s', but it's already taken) to go with the -h sorting:
>
<...>
>  > du -sh *|sort -h|tail

A slightly different approach would be to defer the "human" size to later,
and enable to do any calculation you want manually, then convert to human sizes with "numfmt":

     du -s * \
        | sort -n \
        | awk '{ sum+=$1 ; print } END { print sum, "Total" }' \
        | numfmt --to=iec

One more thing: instead of 'du -s *', perhaps 'du -d1' would work better (depending on your needs), as it will print sizes used only by directories.

- assaf