Finding large folders in macOS
tl;dr: Use du -sh */ | sort -hr
to find large folders or set the "calculate all sizes" option (it's not as cool as doing stuff in your shell).
The other day, I wanted to upgrade macOS and was greeted by a dialog telling me that I did not have enough storage to install the update. Upon checking my storage, I realised that macOS hat about 120GB of my 256GB SSD allocated to “System Storage”.
The accepted solution to fixing this seems to be searching through Library
folders until you find the beefy folders that take a lot of space (likely Docker or Xcode Emulators) and delete those you don’t need. Shouldn’t be too complicated.
Enter Finder: Finder refuses to tell you how big folders are in its list view. You have to inspect the folder individually (either by choosing another view or by pressing cmd + s
). That’s a somewhat tedious task to perform for a few hundred folders.
Luckily, macOS is built on unix and unix is great.
Unix comes with a program called du
. du
estimates disk usage of files and sounds like just the functionality we need. Running du -sh */
inside a folder will display a single entry per file (-s
) and display the usage in a human readable way (-h
).
We can use that output and pipe it to sort
which… well, it sorts lines of text or binary files. Here, we want to use the -h
flag as well so it can sort units like Megabyte and Gigabyte properly and also reverse the order (-r
) so the larges files come first.
That leaves us with the final command du -sh */ | sort -hr
.
~/Desktop
⟩ du -sh */ | sort -hr
78.2G homework/
504K do-not-touch/
428K stuff/
Running this in all the Library folder macOS has will quickly lead us to the big folders.