• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Justin Joyce

Practical tips and tutorials about software development.

  • Standing Invitation
  • Featured Posts
  • Latest
  • About

How to free up disk space

Posted Feb 8, 2023 โ€” Updated Jan 10, 2024

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:

output of `du -sh ./* | sort -h`
last three lines of output of du -sh ./* | sort -h

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:

disk usage inside /Library

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:

disk usage in 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.

Filed Under: Command Line, Tips

Primary Sidebar

Recent Posts

  • Every Built-In Vim Color Scheme (with screenshots)
  • Reverse a string in Python
  • Meeting Cost Calculator
  • Vim find and replace
  • What makes an effective development team

Categories

  • Arrays (5)
  • Command Line (9)
  • Dates (3)
  • Featured (7)
  • Git (7)
  • Golang (5)
  • Javascript (8)
  • Productivity (8)
  • Projects (4)
  • Python (15)
  • Regex (2)
  • Ruby (3)
  • Shell (2)
  • Thoughts (2)
  • Tips (11)
  • Tools (3)
  • Tutorials (1)
  • Vim (4)

Archives

  • July 2024 (1)
  • February 2024 (1)
  • January 2024 (1)
  • December 2023 (1)
  • November 2023 (1)
  • October 2023 (4)
  • September 2023 (1)
  • August 2023 (2)
  • July 2023 (5)
  • June 2023 (3)
  • May 2023 (6)
  • April 2023 (5)
  • March 2023 (5)
  • February 2023 (10)
  • January 2023 (6)
  • December 2022 (7)

Copyright © 2025 ยท Contact me at justin [at] {this domain}

  • Privacy Policy