Last active
August 20, 2020 22:06
-
-
Save sanjay-bhuva/97db494d238a6876cb562a559bc32019 to your computer and use it in GitHub Desktop.
Ubuntu cleanup utility to clean common junk and free up space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to perform some useful linux cleanup operations | |
# 1. Download the file | |
# 2. Make it executable using chmod +x ubuntu-cleanup-utility.sh | |
# 3. Run command below command | |
# sudo ./ubuntu-cleanup-utility.sh | |
REMOVE_LOG_OLDER_THEN_DAYS=1 | |
SNAP_DIR=/var/lib/snapd/snaps | |
# Remove packages no longer required | |
function removeUnnecessaryPackages() { | |
apt-get autoremove | |
} | |
# Clean up APT cache | |
function cleanAPTCache() { | |
apt-get clean | |
} | |
# Clean system logs | |
function clearSystemLogs() { | |
journalctl --vacuum-time=1$REMOVE_LOG_OLDER_THEN_DAYS | |
} | |
# Removes old revisions of snaps | |
# CLOSE ALL SNAPS BEFORE RUNNING THIS | |
function clearSnap() { | |
set -eu | |
snap list --all | awk '/disabled/{print $1, $3}' | | |
while read snapname revision; do | |
snap remove "$snapname" --revision="$revision" | |
done | |
} | |
# Clear thumbnail cache | |
function clearThumbnails() { | |
rm -rf ~/.cache/thumbnails/* | |
} | |
echo "Removing packages no longer required" | |
removeUnnecessaryPackages | |
echo "Cleaning APT cache" | |
cleanAPTCache | |
echo "Cleaning system log older then $REMOVE_LOG_OLDER_THEN_DAYS day(s)" | |
clearSystemLogs | |
echo "Removing older versions of Snap applications" | |
echo "Snaps size before cleaning" | |
du -h $SNAP_DIR | |
clearSnap | |
echo "Snap size after cleanup" | |
du -h $SNAP_DIR | |
echo "Cleaning thumbnails" | |
clearThumbnails | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment