Categories
Blog News

Disk Usage on a mac : a little bash can take you a long way

I’ve been looking for a free solution to see where all the diskspace on my iMac has recently gone to, and so far I found only a few apps. All are to be purchased, and for what wanted this was overkill. I just wanted a quick check on where the source of biggest disk space consumption lay : was it the music collection ? or the movie collection ?

So here’s a quick tip on how to solve this for free, no new tools needed, on a Mac or Unix machine : I introduce to you the ‘du’ command.

DU stands for Disk Usage, and in combination with some switches, it’ll let you quickly and (fairly) easely find out where all those mega- and gigabytes have gone to.

Here’s the line you can use all ready for you – I executed the command in my user directory :

du -d1 -kc | sort -nr

Written out it gives the following command : show me the Disk Usage only to the first Directory level (or Depth) and give (pipe) the results to the sort program and show the reverse output from big to small. If you just use du without sorting, you can add the -h flag to it : this will show you the size in Kilobytes, Megabytes or Gigabytes.

Which gives the following output :


334265428    total
334265428    .
168926644    ./Movies
46947780    ./Library
38262372    ./Music
21862824    ./Documents
17618688    ./Software
16472220    ./Archive
14429940    ./Pictures

This means that there’s 161 GB in my movie collection !! Obviously I need to check what’s going on in there. I can now perform the same command in the movies directory and have the information there to see which directory in there is the largest..

[Update] I just remembered a program I used to use on Windows, and lo and behold, it’s still active, and is multi-platform as it is written in Java. If you need more than that or want something more graphical or extensive, you can also try JDISKREPORT, which is is free to boot!