Re: graphical representation of `du`
Nobody knows that you're in for that, freebsd-questions! 2011/04/05 04:12:40 +0400 Австин Ким avs...@mail.ru = To freebsd-questions@freebsd.org : Sun, 3 Apr 2011 20:57:24 +0100 письмо от Chris Rees utis...@gmail.com: On 3 April 2011 20:26, Австин Ким avs...@mail.ru wrote: Sun, 03 Apr 2011 12:01:24 +0200 письмо от David Demelier demelier.da...@gmail.com: On 02/04/2011 19:30, Chris Rees wrote: On 2 April 2011 18:22, Chris Reesutis...@gmail.com wrote: On 2 April 2011 18:07, Mike Jeaysmike.je...@rogers.com wrote: On Sat, 2 Apr 2011 17:15:04 +0100 Chris Reesutis...@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 2time $ 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 2time2 $ cat time2 7.77 real 0.14 user 0.00 sys YMMV of course! Chris I can't argue with that. If you're a sysadmin and are managing a large system, the sort could take some time. On the other hand, there are times when a sort might be useful. Then again, you could always just comment that line out :) Which reminds me, my sort line above may not sort intuitively in the case where directory names contain characters that precede / in the ASCII character set; for example, mydir-old sorts before mydir/ in ASCII. A quick kludge is to translate slashes into, oh I don't know, say carriage returns before the sort, and then translate them back after the sort, as is done below. An inelegant and inefficient solution, but it works. However, I'm going out on a limb by assuming users won't be running this script under MS-DOS, where this kludge wouldn't work. Another problem with my script above is that in some cases, if you run it on multiple arguments, e. g., dg dir1/subdir dir2/subdir, you can't tell from the output to which parent directory the subdirectory refers; to deal with this problem, the revised version below runs du on each argument one at a time. However, I ended up having to duplicate the main command in the script (once for dg with arguments, and once without), 'cause I'm not clever enough to figure out a way to combine the two cases into one in time to post this. I also had a redundant [^|] in the sed expression which I took out; it shouldn't be necessary, although the script will still mess up if any directory names start with | . Finally, the revised version is repackaged as a proper sh(1) script like your original script rather than as a function, to make it independent of a user's particular shell. Obviously further variations and improvements could be made. Again I'm away from my FreeBSD machine and am writing this on a Mac OS X machine; hopefully I didn't break anything. #!/bin/sh # # dg: `du--graphical' # Usage: dg [dir ...] # # Based on script by Chris Rees # 1459 Sunday, 3 April 2011 # # Modified: 1900 Monday, 4 April 2011 if [ $1 ] then for i in $@ do if [ $2 ] then echo echo $i: fi du -h $i | awk '{FS=\t; print $2\t[$1]}' | tr / '\r' | sort | tr '\r' / | sed -e 's:[^/]*/:| :g' -e 's:\(^\(| \)*\)| \(.*\):\1+-\3:' done
Re: graphical representation of `du`
On Apr 6, 2011, at 11:34 AM, Peter Vereshagin wrote: Again, why don't you guys just use perl to provide a graphical du? I believe perl is just present on every freebsd machine where graphical du is needed. Although it is a common addition, Perl isn't part of the FreeBSD base system. Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
2011/4/6 Peter Vereshagin pe...@vereshagin.org: Again, why don't you guys just use perl to provide a graphical du? I believe perl is just present on every freebsd machine where graphical du is needed. Why on Earth would you use Perl when a simple awk script will do??? Chris ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
Nobody knows that you're in for that, freebsd-questions! 2011/04/06 20:34:42 +0100 Chris Rees utis...@gmail.com = To Peter Vereshagin : CR Again, why don't you guys just use perl to provide a graphical du? I believe CR perl is just present on every freebsd machine where graphical du is needed. CR Why on Earth would you use Perl when a simple awk script will do??? Me? I personally find Perl more usable. 73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB 12F8 0CE1 4AAC A0E2 6627) -- http://vereshagin.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On Wed, Apr 06, 2011 at 08:34:42PM +0100, Chris Rees wrote: 2011/4/6 Peter Vereshagin pe...@vereshagin.org: Again, why don't you guys just use perl to provide a graphical du? I believe perl is just present on every freebsd machine where graphical du is needed. Why on Earth would you use Perl when a simple awk script will do??? Why on earth would you cloud things up with AWK when a simple Perl script would do it?! jerry Chris ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On 02/04/2011 19:30, Chris Rees wrote: On 2 April 2011 18:22, Chris Reesutis...@gmail.com wrote: On 2 April 2011 18:07, Mike Jeaysmike.je...@rogers.com wrote: On Sat, 2 Apr 2011 17:15:04 +0100 Chris Reesutis...@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! :-) Chris ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org -- David Demelier ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On 2 April 2011 15:20, Ryan Coleman edi...@d3photography.com wrote: I found this command: ls -R | grep :$ | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' Which makes this: |-Mar17 |---1300074369-chow |-download |---small |---1300421616-Cunningham |-download |---small But I want to use `du` instead to convert this 2.0M ./Mar17/1300074369-chow/download/small 2.0M ./Mar17/1300074369-chow/download 2.0M ./Mar17/1300074369-chow 2.1M ./Mar17/1300421616-Cunningham/download/small 2.1M ./Mar17/1300421616-Cunningham/download 2.1M ./Mar17/1300421616-Cunningham 4.1M ./Mar17 into this: |-Mar17 [4.3M] |---1300074369-chow [2.0M] |-download [2.0M] |---small [2.0M] |---1300421616-Cunningham [2.1M] |-download [2.1M] |---small [2.1M] I realize it does it backwards and I can live with that... OR mix the two to run the first command and run another command to get the folders total size or something... you know? 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,^,|,' Does it forwards :P [crees@zeus]~/workspace/ports% 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,^,|,' |. [445K] |--net-mgmt [81K] |CVS [5.5K] |zabbix-server [74K] |--files [11K] |CVS [4.5K] |--CVS [4.5K] ... etc... |--net [31K] |pppoa [24K] |--CVS [4.5K] |--files [12K] |CVS [4.5K] |CVS [5.5K] [crees@zeus]~/workspace/ports% Any refinements requested I'll have a look at. Chris ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On 2 April 2011 18:07, Mike Jeays mike.je...@rogers.com wrote: On Sat, 2 Apr 2011 17:15:04 +0100 Chris Rees utis...@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 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On 2 April 2011 18:22, Chris Rees utis...@gmail.com wrote: On 2 April 2011 18:07, Mike Jeays mike.je...@rogers.com wrote: On Sat, 2 Apr 2011 17:15:04 +0100 Chris Rees utis...@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... Chris ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On Sat, 2 Apr 2011 17:15:04 +0100 Chris Rees utis...@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... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
Wow... You rock! Thanks so much! On Apr 2, 2011, at 12:30 PM, Chris Rees wrote: On 2 April 2011 18:22, Chris Rees utis...@gmail.com wrote: On 2 April 2011 18:07, Mike Jeays mike.je...@rogers.com wrote: On Sat, 2 Apr 2011 17:15:04 +0100 Chris Rees utis...@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... Chris ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On Sat, Apr 02, 2011 at 06:30:15PM +0100, Chris Rees wrote: On 2 April 2011 18:22, Chris Rees utis...@gmail.com wrote: On 2 April 2011 18:07, Mike Jeays mike.je...@rogers.com wrote: On Sat, 2 Apr 2011 17:15:04 +0100 Chris Rees utis...@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... Chris PULeesese DO port that . [!!] gary ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix The 7.98a release of Jottings: http://jottings.thought.org/index.php http://journey.thought.org ethic Coming soon to http://transfinite.thought.org: On_Suicide ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
Hi On 2 April 2011 15:20, Ryan Coleman edi...@d3photography.com wrote: I found this command: ls -R | grep :$ | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' What about xdu? http://sd.wareonearth.com/~phil/xdu/ David ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
Chris Rees utis...@gmail.com wrote: Maybe I should port it... +1 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
Well, it looks like it's written for X, which I don't run on any of my servers. Thanks, though. On Apr 2, 2011, at 6:50 PM, David Chanters wrote: Hi On 2 April 2011 15:20, Ryan Coleman edi...@d3photography.com wrote: I found this command: ls -R | grep :$ | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' What about xdu? http://sd.wareonearth.com/~phil/xdu/ David ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On 3 April 2011 01:30, Ryan Coleman edi...@d3photography.com wrote: Well, it looks like it's written for X, which I don't run on any of my servers. Moan, moan, moan. It solves your problem though. David ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
Yeah I don't run these computers to be desktops :) On Apr 2, 2011, at 8:05 PM, David Chanters wrote: On 3 April 2011 01:30, Ryan Coleman edi...@d3photography.com wrote: Well, it looks like it's written for X, which I don't run on any of my servers. Moan, moan, moan. It solves your problem though. David ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On Sat, Apr 02, 2011 at 08:07:43PM -0500, Ryan Coleman wrote: Yeah I don't run these computers to be desktops :) exactly. i Do have x11 and ctwm just to get two xterms. but prefer the console. --besides, xdu takes too long. On Apr 2, 2011, at 8:05 PM, David Chanters wrote: On 3 April 2011 01:30, Ryan Coleman edi...@d3photography.com wrote: Well, it looks like it's written for X, which I don't run on any of my servers. Moan, moan, moan. It solves your problem though. David ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix Journey Toward the Dawn, E-Book: http://www.thought.org The 7.98a release of Jottings: http://jottings.thought.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: graphical representation of `du`
On 3 April 2011 02:25, Gary Kline kl...@thought.org wrote: On Sat, Apr 02, 2011 at 08:07:43PM -0500, Ryan Coleman wrote: Yeah I don't run these computers to be desktops :) exactly. i Do have x11 and ctwm just to get two xterms. but prefer the console. --besides, xdu takes too long. Double moan-bullshit. David ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org