---
title: How I saved 100 GB of disk space on my Mac
teaser: Strategies to reclaim precious disk space on your Mac, and bid farewell to
  the dreaded 'Your disk is almost full' message.
tags: ''
author: Rakesh Arunachalam
published_on: 2024-05-30
---

![Disk-full](https://images.thoughtbot.com/vvxdmyc4md92xk7auj9d4fehek2r_storage%20full.png)

As a mobile developer, the dreaded "Your disk is almost full" message on my Mac
scares me like [cats spotting a cucumber]. But fear not! In this post, I'll
share how I managed to reclaim a whopping 100 GB of precious disk space on my
MacBook. Although the examples in this post might be specific to data generated
during mobile applications development, the strategies outlined for disk space
optimisation are universally applicable to developers across various
technologies. Let's dive in!

## Big wins matter

Deleting large project build files such as "Xcode developer data" might provide
short-term gains, but these won't last as the space will be used again as soon
as we restart development.

![Delete Xcode developer data](https://images.thoughtbot.com/5nm8il0az27r688vpg6yvl07gtmh_Xcode%20developer.png)

Similarly, meticulously deleting numerous small files may yield minor gains, but
the time invested often outweighs the benefits. Example: By selectively deleting
from `Documents` (screenshot), I might eventually gain 1.5 GB but lost 20
minutes in the process while that disk space warning and the new version of
Xcode requiring 27 GB (~13 GB compressed) are still smiling at me.

![Small gains](https://images.thoughtbot.com/34p5qvdampkgh94qy0atgi9t7ghj_Small%20gains.png)

So focus on the big wins that gain maximum disk space first. We can revisit the
minor victories later.

### Time machine backups

According to [Apple], *"With Time Machine, you can back up files on your Mac
that weren’t part of the macOS installation, such as apps, music, photos and
documents."*

Essentially, Time Machine backups provide automatic, incremental backups of a
Mac, allowing users to restore their machine's data to a previous state. While
this feature is useful, the backups ([local snapshots]) can gradually consume
significant disk space over time. Therefore, periodically clearing older backups
can help reclaim valuable storage space on the disk.

These are some commands to check and manipulate your Time machine backups:

```sh
# List snapshots
tmutil listlocalsnapshots /

# Delete snapshots
tmutil deletelocalsnapshots /

# Disable Time machine backups
sudo tmutil disable

# Enable Time machine backups
sudo tmutil enable
```

Personally, my excitement waned when I discovered that Time machine was already
disabled on my MacBook and I ended up freeing no space at the end of this
exercise.

### Delete Node Modules

As a React Native and JavaScript developer, Node modules are an integral part of
my projects. However, if left unchecked, these can occupy a significant amount
of disk space. It's essential to periodically clean up the `node_modules`
directories across all project repositories on our machine.

![Node Modules](https://images.thoughtbot.com/9p6gg76cnvi6h20a2ahddbc4zpyu_Node%20modules.png)

[Delete ALL node_modules] is a fantastic post detailing the process of deleting
`node_modules`. The crux is to run the command below to delete `node_modules`
recursively on all the project repos.

```sh
# Run in a directory where we have all our code
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
```

There are two parts to this command:

`find . -name 'node_modules' -type d -prune -print` is safe to run and looks for
directories with the name `node_modules`.

- `-type d` only looks for directories ignoring files.
- `-prune` is smart and ignores recursive occurences of `node_modules` in
  projects and stops at the parent directory.
- `-print` prints each result on the screen.

`-exec rm -rf '{}' \;` executes the `rm -rf` command on each result of find
where `{}` is replaced by the result. `\;` terminates the command.

Reclaiming nearly 10 GB of free space with just one command felt as satisfying
as a GitHub PR that removes 1000 lines of code.

If you are a Ruby on Rails developer or use technologies that create a lot of
log files, running this command might help you find a few large log files that
can safely be deleted.

```sh
# Run in a directory where we have all our code
du -h ./**/log | sort -rh
```

Sometimes [Homebrew] creates unnecessary files and dependencies that need to be
cleaned up. Running the cleanup command periodically will help keep the Macbook
organised and efficient.

```sh
brew cleanup
```

## Finder tips

### Storage basics

Apple tends to limit what users can do, and the "Storage" in "System Preferences
-> General -> Storage" is no exception. While it appears promising, it has
limitations.

- The "Applications" section allows straightforward app uninstallation.
- The "Developer" section contains Xcode developer data and as mentioned
  previously can provide temporary storage gains.
- For deeper cleaning, the "Documents" section presents various options like
  Large Files, Downloads, Unsupported Apps, and File Browser. All these four
  options are useful in their own way.

![Storage options](https://images.thoughtbot.com/qxairrfni2ag8gj8x3m7go1pnqnn_Screenshot%202024-04-19%20at%2017.48.24.png)

At the end of this exercise, we realise that not much space has been freed. The
files in `Documents` are needed and can't be deleted.

### Advanced Finder

Based on the screenshots, we notice that "System Data" is using a lot of storage
(~172 GB) but "Storage" does not show any more details making us wonder if there
is a magical way to get more information. Follow these steps to know space usage
of "System Data" on the GUI:

- Restart your Mac and let the OS reindex the file system
- Open Finder, click on the Go menu, and hold down the Option (⌥) key.
- This will reveal a hidden "Library" option. Click and choose that option. What
  we see here is the majority of the items shown as "System Data" by Mac.
- In the "Library" folder, switch to the "List view" and sort by size.
- Click on the "View" menu and select "Show View Options".
- Select "Calculate All Sizes" and keep this window open throughout this
  exercise.
- Use Finder like a file tree and keep opening directories you suspect. If the
  sizes are not shown, select the "Calculate All Sizes" for each directory.

**Warning**: Avoid making changes to the "Library" folder unless you're
well-versed as a developer. Modifying this folder without proper understanding
can lead to unintended malfunctioning of your machine.

This exercise pointed me to a lot of interesting directories occupying quite a
lot of disk space on my machine.

### Hidden Dot files

Developers often use dotfiles to customise their machine, including settings for
unix shell (`.zshrc`), text editors (`.vimrc`), version control systems
(`.gitconfig`), and so on. These files allow developers to tailor their workflow
and preferences to suit their needs across different machines or environments.

```sh
# List all files including dotfiles
ls -a ~/
```

These files are typically hidden and Mac "Storage" preferences will not show up
such directories when trying to free up space. Using Finder, press "Command (⌘)
\+ Shift (⇧) \+ . (period)" keys which starts showing all the hidden and
dotfiles. Now, follow the approach outlined in the previous section to
recursively find large files that you can investigate and delete.

## My Free space

Identifying the biggest disk space consumers on my Mac wasn't easy unless you're
a command-line pro. But I managed to do it just by using Finder and the steps
mentioned previously.

### Goodbye Docker

![Docker raw](https://images.thoughtbot.com/7bwjs0a56ksm6xlc9vbcayz0nrmi_Screenshot%202024-03-26%20at%2016.50.05.png)

According to this [Docker Github issue], Docker typically reserves at least 64
GB of storage space even if you are not using it actively or have that many
containers. While the thread provides methods for reducing the size of this
file, hobbyists like myself, may find that deleting the `Docker.raw` file in
`~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw`, which
consumes 64 GB of disk space, works. If you're not actively using Docker,
consider uninstalling it and then delete the `Docker.raw` file.

64 GB gained!

### Unused Android SDKs

Android SDK that includes emulators, platform tools, and various SDKs, can
accumulate consuming significant disk space on your system over time. While
these resources are essential for Android development and function seamlessly
within Android Studio, it's easy to overlook their cumulative storage impact
over the years.

[System images] in Android are implementation codes utilised by various Android
emulators. During my cleanup, I discovered numerous outdated system images for
Android versions 8.0, 8.1, 9.0, and so on, occupying unnecessary space on my
machine. Each image weighed approximately 5 to 10 GB, collectively totalling
around 40 GB of storage. I gained roughly 20 GB by deleting the old unused
system images from `Library/Android/sdk/system-images/`.

20 GB gained!

### Android Virtual Devices (AVDs)

According to [Android], *"The Android Emulator simulates Android devices on your
computer so that you can test your application on a variety of devices and
Android API levels without needing to have each physical device."*

![Android AVD](https://images.thoughtbot.com/sjsu3wwha1ucjus02li7cdc712hy_Screenshot%202024-03-26%20at%2017.58.34.png)

Over time, I noticed that my Emulators in `~/.android/avd` directory grew
significantly to ~66 GB with one particular AVD, my primary "Pixel 3A" emulator,
occupying a whopping 45 GB of storage. This gradual increase in disk usage is
not uncommon for AVDs, as they tend to accumulate cache, snapshots and other
temporary files over time. Just a reminder, the directory where these emulators
live is a dotfile called `.android`, which can be easily spotted using the
Finder tips mentioned earlier.

```sh
# List your Android AVDs
emulator -list-avds

# Delete user data in an AVD
emulator -avd "Pixel_3a_API_31" -wipe-data
```

Using the `-wipe-data` flag when starting the emulator significantly reduced the
storage usage of the "Pixel 3A" emulator to just 10 GB. Starting the emulator
with this flag periodically can help keep storage usage in check.

35 GB gained!

## Cheat code (Grand perspective)

According to [GrandPerspective], *"GrandPerspective is a small utility
application for macOS that graphically shows the disk usage within a file
system."*

![Grand perspective](https://images.thoughtbot.com/1ds7odct2i2lgszjq36ojk9up89x_GrandPerspective%20Users.png)

I found GrandPerspective to be incredibly user-friendly and effective for
visualizing directory storage usage. Its intuitive tree map format provided a
clear overview of storage space allocation, making it easy to identify large
directories of Docker and Android that were consuming significant storage. This
application considers hidden files, dot files, system files that we covered in
the blog post so far thereby serving as the cheat code to free up storage space
on a Mac.

The application is available for free but consider supporting the developers by
downloading from the Mac App Store.

```sh
# To install GrandPerspective using Homebrew
brew install —cask grandperspective
```

## Conclusion

Implementing the solutions outlined in this post helped me successfully reclaim
approximately 100 GB of free space on my Mac. While the results may vary
depending on what's used for Software development, the methods hopefully serve
well in assisting developers to optimise disk storage.

[cats spotting a cucumber]: https://www.youtube.com/watch?v=oDpQ2uGLUKU
[Apple]: https://support.apple.com/en-gb/guide/mac-help/mh35860/mac
[local snapshots]: https://support.apple.com/en-gb/102154
[Delete ALL node_modules]: https://dev.to/trilon/how-to-delete-all-nodemodules-folders-on-your-machine-43dh
[Homebrew]: https://brew.sh/
[Docker Github issue]: https://github.com/docker/for-mac/issues/2297
[System images]: https://developer.android.com/topic/generic-system-image
[Android]: https://developer.android.com/studio/run/emulator
[GrandPerspective]: https://grandperspectiv.sourceforge.net/
