DEV Community

JuanPablo
JuanPablo

Posted on

Recovering OSX disk space

Warning: Be careful about these commands, before applying these, remember, you are deleting files and data. Be aware of what are you deleting. You could lose data forever.

I wrote this post because when you are developing you depend on tools, dependencies, docker images, etc. And in some moment your disk is full.

Using the next commands you can recover some disk space used.

Recover some disk space used by:

Brew

brew cleanup
Enter fullscreen mode Exit fullscreen mode

Docker

If you are using docker, check docker's directory

du --max-depth=1 -h ~/Library/Containers/com.docker.docker/Data
Enter fullscreen mode Exit fullscreen mode

If it is using too much space you could apply a prune. Remember this command will delete docker's images and volumes.

If you have important data, back up it before.

docker system prune -a --volumes
Enter fullscreen mode Exit fullscreen mode

Cache directories

Check your Cache directory and delete some of the directories that use more disk space (in my case those were Spotify, pip, and Cypress).

du --max-depth=1 -h ~/Library/Caches/ | sort -hk1
Enter fullscreen mode Exit fullscreen mode

I hope that these commands could be useful for recovering some space on your disk.

Do you have other tips to recover disk space on OSX? please add those in the commentaries.

Top comments (0)