For the next few months, I will have a “script of the week” each week: just some tiny little scripts I’ve developed over the years that I happen to find particularly useful.

Today’s is a shell script called sizes. It’s a fairly simplistic interface to the du commands which just shows you all files and directories in the current directory that are larger than one megabyte.

Here’s an example of running it in my /Library directory:

~/Library $ sizes
2.8M   Scripts
3.9M   Components
5.6M   Java
6.0M   QuickTime
6.1M   PreferencePanes
7.6M   TexPackages
 12M   Keychains
 15M   Fonts
 20M   Preferences
 36M   Logs
 51M   Lisp
 55M   Emacs
 86M   Backups
398M   Application Support
1.7G   Caches

Here’s the script:

#!/bin/sh

du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
    egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/sizes.$$

egrep '^ *[0-9.]*M' /tmp/sizes.$$
egrep '^ *[0-9.]*G' /tmp/sizes.$$

rm -f /tmp/sizes.$$
 

One Response to Script of the week: sizes

  1. anon says:

    du -sx *| egrep ‘^[0-9]{3,}’ | sort -n| awk ‘BEGIN {u[0]=k;u[1]=”M”;u[2]=”G”;} {for (i=3;i>0;–i) { if ( $1 > 1024 ^i) {printf “%.2f%st%sn”,($1 / 1024^i),u[i],$2;next}}}’

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Set your Twitter account name in your settings to use the TwitterBar Section.