Running out of space on a developer's machine
Dan Benitah
Posted on December 20, 2023
As developers, we often find our hard drives mysteriously filling up, slowing down our workflow.
First reflex is often to remove the waste and for developers, that includes downloaded packages that linger until we return our unused projects.
Let's explore a simple, yet powerful command-line I came across to reclaim hat precious disk space, making room for more coding and less clutter.
So I started with a 250 GB SD full
The commands we will need
Disk space
Command to get the disk space (I used an SD card smaller than my project folder until full).
diskutil info -all
You can also use
Remove a child folder from a directory
Looking for a command to recursively remove child node_module folder, I found the following command at https://stackoverflow.com/a/70549487/4819888 (it seems to have equivalents for Windows and Linux too)
find . -name '<folder to remove>' -type d -prune -print -exec rm -rf '{}' \;
Cleaning up node_modules folders
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
After running this command and clearing 22 node_module folders, it went down to 76GB
Cleaning up bin folders
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
After running this command and clearing down 490 bin folders, I had a further 20 GB of additional free space.
I was thinking next we could tackle python packages but I could not find consistent naming convention though "pip" was what brought back most results. Also more on dangling docker images here. Anyway...
Conclusion
So here we are with a reduction of 78.43% of the space my projects took in no time.
What other folders shall we look to remove? Have you noticed similar savings?
What other tips might you have to share?
Posted on December 20, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.