List the largest folders on your Mac in one keystroke with Keyboard Maestro or Quicksilver


In preparation for backing up my large Dance Music library to Dropbox (in order to sync it between my iMac and MacBook Air), I wanted to start by deleting all the songs I won’t miss. Finding individual files over a certain size is easy via the Finder, but I wanted to find out which folders (i.e. albums) were over 500MB so I could tackle them first.

There is no Folder size option in Finder’s search (afaik), so I did some Unix command research and found the wonderful du (short for disk usage). By default, du lists the folder sizes as multiples of 512 bytes, but you can easily change that to 1024 bytes with the -k flag. So, if you wanted to see the size of all your Dropbox folders, you would run the following command in Terminal:

$ du -k /path/to/Dropbox/*

If you’re already in the Dropbox directory:

$ du -k *

In my case, I wanted to filter the list to only include folders that are over 500MB. That can be easily done using the Unix pipeline feature (where you can feed the output of one command into another command), and AWK:

du -k ~/Dropbox/* | awk '$1 > 500000'

The du command outputs two values, the folder size, and the folder path. Awk captures those values inside the $1 and $2 variables, respectively.

To sort the results by largest folder size, we can add another pipe and use the sort command:

du -k ~/Dropbox/* | awk '$1 > 500000' | sort -nr

Now that we have the full command, we can have the results a keystroke away using either Keyboard Maestro or Quicksilver.

For Keyboard Maestro, you can download my macro and import it in your Keyboard Maestro. Here are 3 things you might want to change, depending on your needs and preferences: the keyboard shortcut, the folder you want to analyze, and the minimum folder size.

If you want to set everything up manually in Keyboard Maestro, create a new macro, set it to be triggered by your desired keyboard shortcut, then add an Execute Shell Script action, select display results in a window in the second dropdown, and paste your du command, as shown below:

keyboard maestro macro to display all folders over a certain size

For Quicksilver, you’ll need to install the Terminal plugin and create a custom trigger. Here’s how:

1) Go to Quicksilver’s Preferences (via the keyboard shortcut ⌘, or via the Menu Bar icon, or via right-clicking on the Dock icon)

2) Click on the Plugins tab at the top right, click on All Plugins on the left, then click on Terminal Plugin to install that plugin, as shown below:

Quicksilver Terminal Plugin

3) Click on the Triggers tab at the top, then click on the + button at the bottom and select Hot Key. When the sheet slides down, type a period (.) to invoke the text entry field in the first pane. Paste or type your du command in the first pane. Press the tab key to move to the next pane, and start typing Run a Text Command until you see Run a Text Command in Terminal. Click Save.

Show Clipboard Quicksilver Trigger

4) Double-click on None under the Trigger column for your new custom trigger (or click the i button at the bottom). Click inside the Hot Key field (if it’s not already flashing), then type in your desired keyboard shortcut.

Quicksilver Hot key trigger to show clipboard contents

Now, whenever you want to see a list of your largest folders, simply type your keyboard shortcut. If, instead of a specific folder like Dropbox, you want to analyze your entire Home directory, you can use the following command:

du -k -I Library ~/* | awk '$1 > 500000' | sort -nr

This particular example shows how you can use the optional -I flag to exclude certain folders — the Library folder in this case — from the results.