🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #276

Re: sort du output

#276
From: Peer Landa
Date: Tue, 04 Aug 1992 00:45
41 lines
1594 bytes
Patrick Lobo writes
> 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


A even more simple solution is:
ls -l | sort -nr +3 

-- peer
Technical Details
Message-ID: <1992Aug4.004512.6311@leland.Stanford.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!leland.Stanford.EDU!news
References: <1992Aug3.205728.2143@oracle.us.oracle.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.unix.shell
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!leland.Stanford.EDU!news
From: peer@ccrma.stanford.edu (Peer Landa)
Subject: Re: sort du output
Message-ID: <1992Aug4.004512.6311@leland.Stanford.EDU>
Sender: news@leland.Stanford.EDU (Mr News)
Organization: DSO, Stanford University
References: <1992Aug3.205728.2143@oracle.us.oracle.com>
Date: Tue, 4 Aug 92 00:45:12 GMT
Lines: 44