Last active
February 28, 2023 06:29
-
-
Save mohammed-bamatraf/05cdff5c2241c0d60382258e4e1324fc to your computer and use it in GitHub Desktop.
Ubuntu cleaner
This file contains hidden or 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 | |
#Remove old Kernels | |
uname -a | |
IN_USE=$(uname -a | awk '{ print $3 }') | |
echo "Your in use kernel is $IN_USE" | |
OLD_KERNELS=$( | |
dpkg --list | | |
grep -v "$IN_USE" | | |
grep -Ei 'linux-image|linux-headers|linux-modules' | | |
awk '{ print $2 }' | |
) | |
echo "Old Kernels to be removed:" | |
echo "$OLD_KERNELS" | |
sleep 10 | |
for PACKAGE in $OLD_KERNELS; do | |
yes | apt purge "$PACKAGE" | |
done | |
#Removes old revisions of snaps | |
#CLOSE ALL SNAPS BEFORE RUNNING THIS | |
set -eu | |
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' | | |
while read snapname revision; do | |
snap remove "$snapname" --revision="$revision" | |
done | |
#Other cleaning | |
sudo journalctl --vacuum-time=3d | |
sudo apt-get autoclean | |
sudo apt-get clean | |
sudo apt-get autoremove | |
rm -rf ~/.cache/thumbnails/* | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment