DEV Community

Margaret W.N
Margaret W.N

Posted on

Time to Free up Space on Ubuntu.

Out of Space? Welcome to the club. Time for some space hunt. Here are some techniques that came through for me, today. You might want to start with the last one, it will save you so much work.

  • Remove all unused packages.
sudo apt-get autoremove
Enter fullscreen mode Exit fullscreen mode
  • Clear the APT cache.

Check the cache size:

sudo du -sh /var/cache/apt 
Enter fullscreen mode Exit fullscreen mode

Clear cache

sudo apt-get clean
Enter fullscreen mode Exit fullscreen mode
  • Clear systemd journal logs. This freed up a good amount of space.

Check the space occupied:

journalctl --disk-usage
Enter fullscreen mode Exit fullscreen mode

Clean out some logs. You might want to read about this: Clearing systemd journal logs in linux. But if you are in dire need of space and have no time, use the command below. It will clear all the logs older than 2 days.

sudo journalctl --vacuum-time=2d
Enter fullscreen mode Exit fullscreen mode
  • Remove older versions of Snap applications Check the space occupied
du -h /var/lib/snapd/snaps
Enter fullscreen mode Exit fullscreen mode

Create a script file, add the lines below, and save. I saved mine as script.sh on Home directory.

set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
    done
Enter fullscreen mode Exit fullscreen mode

Give the file execute permissions

chmod 0700 script.sh
Enter fullscreen mode Exit fullscreen mode

Run the script to remove older packages.

sudo ./script.sh
Enter fullscreen mode Exit fullscreen mode
  • Uninstall apps you don't use. Stop saving them for the future! Easy for me to say but this was hard for me. I resorted to deleting everything I haven't used in the past two months, or anything with an online alternative.

All the above freed up about 3 to 4 GB, then came the mother of all space eaters, my trash! Quite embarrassing and funny cause I did not think of the trash at all until I installed Stacer and the analytics were screaming at me: Take out the trash!

  • Install Stacer and let the system cleaner do the work for you. You can search ubuntu software or use the command below to install.
 sudo apt install stacer
Enter fullscreen mode Exit fullscreen mode

That's it for day 70: 100 days of code
Lets do this again tommorrow

Top comments (8)

Collapse
 
bimlas profile image
bimlas

I tend to do the same processes. A little addition:

  • rm -rf ~/Dropbox/.dropbox.cache/*
  • Browser -> History -> Clear current history -> Cache
    • Clear browser cache
  • rm -rf ~/.var/app/REMOVED_APP
    • Data may remain after Snaps have been removed
  • rm -rf ~/.config/JetBrains/IntelliJIdeaPREVIOUS/
    • You can delete directories of previous versions of IDEA
  • Vagrant / VirtualBox: Move virtual machine to another drive
  • Run git prune in repositories
Collapse
 
mtee profile image
Margaret W.N

Awesome! I'll definitely try this. I might end up with more space. Thank you!

Collapse
 
titanhero profile image
Lex

So cool.

Collapse
 
mtee profile image
Margaret W.N

😊

Collapse
 
kaxusi profile image
kaxusi

Thanks

Collapse
 
mtee profile image
Margaret W.N

Your welcome

Collapse
 
mcastellin profile image
Manuel Castellin

I really should take the time to read the journalctl documentation πŸ˜… Awesome tips @mtee !

Collapse
 
mtee profile image
Margaret W.N

πŸ˜‚ You should, though times like this call for a quick fix.

I'm glad you found them useful 😊