🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #274

Re: sort du output

#274
From: Patrick Lobo
Date: Mon, 03 Aug 1992 20:57
33 lines
1739 bytes
In article <1992Jul31.035445.24776@latcs1.lat.oz.au> wongm@latcs1.lat.oz.au (/home/pgrds/wongm) writes:
>Hello,
>  I have a simple question to ask, ie when using du command, how can
>  can we have the listing sorted with the file size as sort key.
>
>  I tried : du | +0 -1 but this will not give correct result,
>  since if we have :
>
>  file    size
>  ----    ----
>  A       10
>  B       2
>  C       3
>
>  The outout from the pipeline is "
>
>  10	./A
>  2		./B
>  3		./C
>
>  How can we do it correctly, do we have to pipe the field 0 from
>  du to bc or some similar command to do that ?

A simple solution is to do something like this

du | sort -r +0 -1 | awk '{ printf("%-60s %s\n", $2, $1); }'

the sort -r is to reverse the sort according to file size.  The -60s in the
printf statement assumes that pathnames will not exceed 60 characters length.
You need to modify this value of 60 to suit your purpose.  The output is
formatted nicely with the above values though.

Patrick Lobo
Technical Details
Message-ID: <1992Aug3.205728.2143@oracle.us.oracle.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sun-barr!ames!pacbell.com!pacbell!oracle!unrepliable!bounce
References: <1992Jul31.035445.24776@latcs1.lat.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sun-barr!ames!pacbell.com!pacbell!oracle!unrepliable!bounce
Newsgroups: comp.unix.shell
From: plobo@dvlseq.us.oracle.com (Patrick Lobo)
Subject: Re: sort du output
Message-ID: <1992Aug3.205728.2143@oracle.us.oracle.com>
Sender: usenet@oracle.us.oracle.com (Oracle News Poster)
Nntp-Posting-Host: dvlseq
Organization: Oracle World HQ, Redwood Shores, California
References: <1992Jul31.035445.24776@latcs1.lat.oz.au>
Date: Mon, 3 Aug 1992 20:57:28 GMT
X-Disclaimer: This message was written by an unauthenticated user
              at Oracle Corporation.  The opinions expressed are those
              of the user and not necessarily those of Oracle.
Lines: 35