graphical representation of `du`

Chris Rees utisoft at gmail.com
Sun Apr 3 19:57:56 UTC 2011


On 3 April 2011 20:26, Австин Ким <avstin at mail.ru> wrote:
> Sun, 03 Apr 2011 12:01:24 +0200 письмо от David Demelier <demelier.david at gmail.com>:
>
>> On 02/04/2011 19:30, Chris Rees wrote:
>> > On 2 April 2011 18:22, Chris Rees<utisoft at gmail.com>  wrote:
>> >> On 2 April 2011 18:07, Mike Jeays<mike.jeays at rogers.com>  wrote:
>> >>> On Sat, 2 Apr 2011 17:15:04 +0100
>> >>> Chris Rees<utisoft at gmail.com>  wrote:
>> >>>
>> >>>> du -h . | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) 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++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' | sed
>> >> -e 's,^[^1-9]*\([^___CTRL-V+TAB______]*\)____CTRL-V+TAB_____*\(.*\)$,\2
>> >> \[\1\],;s,[^-][^/]*/,--,g;s,^,|,'
>> >>
>> >> That does exactly the same --  where 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:  I'm writing this on a Mac OS X machine, not on a FreeBSD machine, at the moment, but hopefully this'll still work.
> Also, the following will mess up if you have directories whose names begin with "|".)
>
> # dg:  `du--graphical'
> # Usage:  dg [dir ...]
> # Based on script by Chris Rees
> # 1459 Sunday, 3 April 2011
>
> dg ( ) {
>  du -h "$@" |
>    awk '{FS="\t"; print $2"\t["$1"]"}' |
>    sort |
>    sed -e 's:[^/]*/:| :g' -e 's:\(^\(| \)*\)| \([^|].*\):\1+-\3:'
>  return
>  }

I used the awk a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--]  etc to
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++]=$2} END { for (j=i-1; j>=0;) print
a[j--] }' >/dev/null 2>time2
$ cat time2
        7.77 real         0.14 user         0.00 sys

YMMV of course!

Chris


More information about the freebsd-questions mailing list