DEV Community

Dan Benitah
Dan Benitah

Posted on

Running out of space on a developer's machine

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

256GB full SD card

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
Enter fullscreen mode Exit fullscreen mode

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 '{}' \;
Enter fullscreen mode Exit fullscreen mode

Cleaning up node_modules folders

find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
Enter fullscreen mode Exit fullscreen mode

After running this command and clearing 22 node_module folders, it went down to 76GB

70% reduction disk space removing node_module folders

Cleaning up bin folders

find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
Enter fullscreen mode Exit fullscreen mode

After running this command and clearing down 490 bin folders, I had a further 20 GB of additional free space.

space left after removing node_module folders and bin folders

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?

Top comments (0)