DEV Community

loading...
Cover image for How to clean up disk space on Ubuntu server

How to clean up disk space on Ubuntu server

CrazyOptimist
https://crazyoptimist.net/about
Updated on ・1 min read

If you are running your own cloud instances and use them for development purposes, their capacities would probably be limited and sometimes you might notice that the disk space is too low.

TL;DR

Remove unnecessary system packages and package caches

sudo apt-get --purge autoremove
sudo apt-get autoclean
sudo apt-get clean
Enter fullscreen mode Exit fullscreen mode

Remove system log except for the last 3 days

Check it first:

journalctl --disk-usage
Enter fullscreen mode Exit fullscreen mode
sudo journalctl --vacuum-time=3d
Enter fullscreen mode Exit fullscreen mode

Clean up snap

Check it first:

du -h /var/lib/snapd/snaps
Enter fullscreen mode Exit fullscreen mode

This is a bash script.

#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
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

Please add more in the comment section if you have another ones.

Happy coding! :)

Discussion (0)