How to free some disk space
By Tomasz Kuczma
I’m a Linux guy. That’s my favorite software development environment. I love its minimalism, and I’m delighted with my low resource usage Xubuntu distribution. Unfortunately, Linux partition needs to share my Yoga 500GB SSD drive with Windows 10 so I can play some games from time to time. Yes, on the integrated Intel UHD620 graphic (Intel i5-8250U CPU) but that’s a different story about portable laptop tradeoffs. I ended up with a 30GB Linux partition to preserve some space for games on Windows partition. Recently, I’ve noticed that disk space is running out on the Linux partition. How to clean it up?
Find suspects!
First of all, localize top suspects using du
command
sudo du -sch /* 2>/dev/null | sort -h
Suspects should be in /var
, /opt
, /usr
and of course /home
.
For more details check subdirectories (don’t forget about files/folders starting with .
like .config
in home folder)
sudo du -sch /opt/{.[^.]*,*} 2>/dev/null | sort -h
sudo du -sch ~/{.[^.]*,*} 2>/dev/null | sort -h
On my machine I found problems with:
- IntelliJ Idea (and family) config files
~/.IdeaIC*
- IntelliJ Idea (and family) installation dir (I install them in
/opt/{idea,pycharm}
) - Maven cache
~/.m2/repository
- Journal logs
/var/log/journal
- Docker images
- Google chrome config dir
~/.config/google-chrome/
Sometimes the problem can be also with apt cache and unused packages or in the trash.
Free your space
IntelliJ Idea (and family) creates a new config dir for every released version. Just remove old versions. IntelliJ Idea installation is huge (~ 1GB) but there is nothing we can do about it besides using a version without internal JVM. Pycharm and Clion also take 1GB each.
Maven cache can be removed too!
It can grow very quickly.
In my previous workplace, I cleaned it every 6 months to restore ~10GB of disk space (mostly because of old internal company artifacts which were released at least once a week).
Next mvn install
run will just take a little longer to download used artifacts again.
Journal logs were my biggest surprise here. Logs occupied 1GB which I reduced to 50MB by retaining only the past two days of logs:
sudo journalctl --vacuum-time=2d
Think twice if you want to run it on a server.
Docker is usually the biggest offender. Stop all containers and remove them all and images:
docker system prune -a --volumes
Think twice if you want to run it on a server - see docs
.
Next docker-compose up
execution will download fresh images.
Google chrome config dir ~/.config/google-chrome/
was quite heavy too.
I saved almost 1 GB by removing ~/.config/google-chrome/Default/Service\ Worker/CacheStorage
and ~/.config/google-chrome/Default/Application\ Cache
.
But honestly, not sure for how long :)
Problems with apt cache and unused packages can be easily resolved with:
sudo apt autopurge && sudo apt autoclean
Result
In the end, I restored 5 GB of disk space lost on the garbage data (after re-fetching current docker images). In my tiny disk use case, it’s over 16% of total disk space!
Let me know where you find disk usage problems :)
Software engineer with a passion. Interested in computer networks and large-scale distributed computing. He loves to optimize and simplify software on various levels of abstraction starting from memory ordering through non-blocking algorithms up to system design and end-user experience. Geek. Linux user.