From owner-freebsd-questions@FreeBSD.ORG Sun Apr 3 19:57:56 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B6C82106566C for ; Sun, 3 Apr 2011 19:57:56 +0000 (UTC) (envelope-from utisoft@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 420248FC12 for ; Sun, 3 Apr 2011 19:57:55 +0000 (UTC) Received: by bwz12 with SMTP id 12so4485539bwz.13 for ; Sun, 03 Apr 2011 12:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=WyihX/C5Mx5oBnnaDrrIqSDK0fkQtt1iF2vSgZWchXM=; b=Rubqgz9OzX6uizM9OBwEB0GrRkARFY6s+d9nRtnjWhhJNbiubVYp2tyuBxaqPjqdUM l4uQ5JY+jkUdcX3GnEygkh2PYbY+CsBPNKAhImk7mkC1hpreNML936gpH0pGHWsN9zGU gpp74mTXCAtTiaHpC18kxUZndkDUIg59WbrYI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:content-type:content-transfer-encoding; b=UUSvgz+5sfVCpiMZw6jzYOssJt5q1g8wrWVemPW5lG2wvgSiuSLO+IWv7F4PnyhWSj ffpz4UKlnLk+c5gmh0LJD9T2u6NUKSmnQS1ByFqax1hY0BI31ZCGVVXuZTwXYwVeblUI 4ZcyE0lkmsUJRGyN93CUfDEuAqu4lbMxOx2SA= Received: by 10.204.7.17 with SMTP id b17mr1517820bkb.214.1301860674097; Sun, 03 Apr 2011 12:57:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.205.64.142 with HTTP; Sun, 3 Apr 2011 12:57:24 -0700 (PDT) In-Reply-To: References: <0DD2BF5C-7387-4AFA-BF43-B1683F3773E8@d3photography.com> <4D984574.2050402@gmail.com> From: Chris Rees Date: Sun, 3 Apr 2011 20:57:24 +0100 Message-ID: To: =?KOI8-R?B?4dfT1MnOIOvJzQ==?= , freebsd-questions@freebsd.org Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: quoted-printable Cc: Subject: Re: Re[2]: graphical representation of `du` X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: utisoft@gmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Apr 2011 19:57:56 -0000 On 3 April 2011 20:26, =E1=D7=D3=D4=C9=CE =EB=C9=CD wrote: > Sun, 03 Apr 2011 12:01:24 +0200 =D0=C9=D3=D8=CD=CF =CF=D4 David Demelier = : > >> On 02/04/2011 19:30, Chris Rees wrote: >> > On 2 April 2011 18:22, Chris Rees =9Awrote: >> >> On 2 April 2011 18:07, Mike Jeays =9Awrote: >> >>> On Sat, 2 Apr 2011 17:15:04 +0100 >> >>> Chris Rees =9Awrote: >> >>> >> >>>> du -h . | awk '{a[i++]=3D$0} END {for (j=3Di-1; j>=3D0;) print a[j-= -] }' | >> >>>> awk '{print($2" ["$1"]");}' | sed -e 's,[^-][^/]*/,--,g' -e 's,^,|,= ' >> >>> >> >>> >> >>> I confess to being impressed... >> >>> >> >> >> >> Yeah, but perhaps I should have used sed instead of the second awk; >> >> fewer processes: >> >> >> >> du -h | awk '{a[i++]=3D$0} END {for (j=3Di-1; j>=3D0;) print a[j--] }= ' | sed >> >> -e 's,^[^1-9]*\([^___CTRL-V+TAB______]*\)____CTRL-V+TAB_____*\(.*\)$,= \2 >> >> \[\1\],;s,[^-][^/]*/,--,g;s,^,|,' >> >> >> >> That does exactly the same -- =9Awhere I've put ____CTRL-V+TAB______ = you >> >> have to type Ctrl-V, then a literal [::tab::] key; BSD sed doesn't do >> >> \t. >> >> >> >> Chris >> >> >> > >> > Final version: >> > >> > http://www.bayofrum.net/~crees/graphical_du.sh >> > >> > Maybe I should port it... >> > >> >> Thanks! This rocks! :-) >> > > What a fun thread :) > > Here's my two cents, written as an sh(1) function that you can tack on to= the end of your .profile or .shrc: > (Caveats: =9AI'm writing this on a Mac OS X machine, not on a FreeBSD mac= hine, at the moment, but hopefully this'll still work. > Also, the following will mess up if you have directories whose names begi= n with "|".) > > # dg: =9A`du--graphical' > # Usage: =9Adg [dir ...] > # Based on script by Chris Rees > # 1459 Sunday, 3 April 2011 > > dg ( ) { > =9Adu -h "$@" | > =9A =9Aawk '{FS=3D"\t"; print $2"\t["$1"]"}' | > =9A =9Asort | > =9A =9Ased -e 's:[^/]*/:| :g' -e 's:\(^\(| \)*\)| \([^|].*\):\1+-\3:' > =9Areturn > =9A} I used the awk a[i++]=3D$0} END {for (j=3Di-1; j>=3D0;) print a[j--] etc t= o reverse the order, rather than alphabetise it because it's quicker: $ du -h . | time sort >/dev/null 2>time $ cat time 8.17 real 0.03 user 0.00 sys $ du -h . | time awk '{a[i++]=3D$2} END { for (j=3Di-1; j>=3D0;) print a[j--] }' >/dev/null 2>time2 $ cat time2 7.77 real 0.14 user 0.00 sys YMMV of course! Chris