DEV Community

Cover image for Getting back that precious disk space

Posted on

Getting back that precious disk space

Hello devs,

I you're like me and you like to try things out, work on several projects in several languages, chances are that you've been cluttering your computer with gigabytes of files that are not worth keeping.

I'm talking about all the cached packages from package managers, old docker images, and containers you started without the --rm flag.

This post is an attempt at regrouping the commands to clear that space. It's written for GNU+Linux users and will probably work for Mac. Some of the commands will also work on Windows (but then if you're doing dev on Windows I'm deeply sorry for you).

If you want to go along and execute the commands, start by checking your disk usage with df -h first so you know how much space you'll get back :)

WARNING: we're going to delete files here! It shouldn't cause any issue because it's only cached files that you can easily get back, but be careful about following a random blog post on the internets telling you to run a bunch of rm -rf commands ;) I shall not be held responsible for any damage caused by executing the commands described below.

I'm starting this article with 94 Gb free on /.

npm (javascript)

npm cache clean --force
yarn cache clean
rm -r ~/.cache/typescript/*

composer (php)

composer clear-cache

cargo (rust)

There is no baked in command for that. See GitHub issue.

rm -rf ~/.cargo/git ~/.cargo/registry

We don't delete the whole ~/.cargo folder as it might contain useful binaries in bin/.


docker system prune -a

I like this command because it tells you how much disk space you got back after running it, and it really removes everything not currently in use. If you've been using docker for while and never used it, you might get as much as 40 Gb or more back! (yes images take up space!)

pip/pipenv (python)

rm -r ~/.cache/pip{,env}
rm -r ~/.local/share/{virtualenvs,jupyter}


go clean -cache -modcache -i -r

The -i flag causes clean to remove the corresponding installed archive or binary (what 'go install' would create). The -r flag causes clean to be applied recursively to all the dependencies of the packages named by the import paths.


Nope, just kidding.

some non-dev stuff

While we're at it...

rm -r ~/.cache/{mozilla,chromium,thumbnails}

You might want to have a look into this folder, as it's quite possible that a game you played 20 minutes in 2011 is taking up 3 Gb... du -sh ~/.cache/*.

Let's not forget the package managers!

Archlinux commands (BTW, I use Arch!):

sudo pacman -Sc (add another c to really remove everything)
yay -Sc

For Debian/Ubuntu/Mint users:

sudo apt-get clean
sudo apt-get autoclean

For Fedora/CentOS users:

dnf clean all


Please let me know in the comments how much disk space you got back! I had 94 Gb free at the beginning, now it's showing 128 Gb! That's 34 Gb back from the dead!! :)

Header image "GrandPerspective disk map" by Lars Plougmann is licensed under CC BY-SA 2.0

Top comments (2)

fluffynuts profile image
Davyd McColl

Also, using a tool like QDirStat (or the windows port WinDirStat) can help to pinpoint where that space is going (:

elabftw profile image

I'm partial to baobab myself. Installed by default on some distribs (fedora).