Part of being a developer means constantly downloading new packages, updates, codebases, etc. Eventually, your computer starts to fill up. This post details how to clean it out.
The du
command
This is the disk usage
command, and it is key to figuring out what is using your space. Here’s my usual workflow:
Starting at the home directory, check the disk usage of all directories:
# cd with no args drops you into your home directory
cd
# du -sh summarizes by directory in human-readable output
# "./*" means "directories inside my current directory"
# Then pipe the result to "sort -h", which sorts based on# human readable filesizes
du -sh ./* | sort -h
The above command outputs something like this:
There’s a clear leader in disk usage in that screenshot, so let’s dig more into /Library
, running du -sh ./* | sort -h
a few more times:
Again, there are some clear outliers here. Digging down further, /Messages
was almost entirely composed of attachment files from my text messages, which I’d rather not delete. /Application Support
consists of files written by applications which they might need in order to run correctly, so let’s try /Caches
:
There we go! These don’t look like they’re essential, so some of them can probably be removed. A simple rm -rf
on the directory will delete it and free up its disk space.
That’s about it! I did this whole process earlier today (and forgot to take screenshots, of course) and freed up about 12G of space on my computer.
Other places to free up space
Docker
If you use docker, periodically running docker system prune
or docker system prune -a
helps; docker won’t clean up after itself unless you tell it to, and it takes up a lot of space by necessity. I run this every few months and it frees up a few gigs each time.
Homebrew
Brew seems to be the default package manager for mac, and it also needs manual cleaning on occasion. Try brew cleanup --prune=all
to free up some space.
Node Modules
If you use javascript, you’re familiar with node_modules
and how it tends to bloat over time. Going through your repos every once in a while and rm -rf node_modules
can’t hurt; each directory is usually quite a bit smaller after I re-npm install.