How to clean disk on macOS without paid utilities and subscriptions
Familiar picture: you open the "Storage" tab in macOS settings, and there are gigabytes filled with the "System Data" category. Where the space went, the system doesn't really explain. You start looking for a solution, and the search engine immediately offers all-in-one tools with pretty interfaces and a forty dollar price tag for an annual subscription.
Paying for something to delete cache once a month is usually not what a developer wants. In search of a lightweight alternative, I came across the cleanmac project by developer Haralambi Dobrev (hkdobrev). It's a regular bash script that quietly cleans up garbage from the system.
Why you need a separate cleanup script
Most developers keep a zoo of tools on their machines. Xcode accumulates dozens of gigabytes in the DerivedData folder. Docker stores layers of old images. Package managers like npm and yarn cache for years.
Manually remembering all paths and commands is time-consuming. Third-party GUI apps often run in background processes, send notifications, and consume RAM. The cleanmac script solves the problem directly: you run it in the terminal, it goes through known directories, frees up space, and exits.
I'll make a note: the author recently archived the repository and recommends checking out the newer Mole tool. But cleanmac.sh is written so transparently that it's easy to extract snippets for your own dotfiles or use as a ready-made recipe.
What exactly cleanmac cleans
There's no magic inside the script—just commands to clear specific work-related debris.
The script checks four main groups of junk:
- Development cache: DerivedData folders and Xcode archives, npm and yarn cache.
- Containers: unused layers and stopped Docker containers.
- System junk: application logs, Safari cache, user caches in 6 and Trash contents.
- RAM: disk cache reset via system utility call 7.
It's convenient that system cache deletion is configurable by age. By default, the script leaves files created within the last 7 days. If you don't want to touch fresh cache, you can pass a different interval via arguments.
How to run the script
Installation boils down to cloning the repository:
0Before removing gigabytes of files, it's prudent to preview what the script will delete. A safe mode is available for this purpose:
1The 8 flag will list paths without actually deleting data. If the list suits you, run the cleanup:
2The script will request superuser rights if it needs to delete system logs or perform a RAM reset.
What's inside and what you can learn from it
For those who write their own automation scripts, cleanmac is interesting as an example of clean bash code. It has well-structured argument handling, checks for installed utilities (for example, whether Docker is installed in the system), and output formatting.
If you don't need the full functionality, you can extract only the functions you need. For example, lines for cleaning DerivedData:
3Or the Docker image cleanup call:
4Adding these couple of commands to an alias in your zshrc is often faster and safer than installing closed software with opaque telemetry.
Who will find this useful
The project is suitable for those who:
- Work on a Mac with a small 256 or 512 GB SSD.
- Actively develop for iOS or web, where caches fill up the disk in a couple of weeks.
- Prefer open shell scripts over closed paid utilities.
- Want to peek at ready-made commands for their own system maintenance scripts.
Even with the repository's archived status, cleanmac perfectly demonstrates a simple approach to routine tasks: instead of heavy programs, sometimes thirty lines of Bash are enough. If you need an actively maintained tool with an interactive interface right in the terminal, check out the Mole mentioned by the author. For quick one-time cleanup, cleanmac will do the job too.
Related projects