Last active
February 3, 2023 12:47
-
-
Save wyodeb/3bb57e6e470a025e7a35680b6eccdf77 to your computer and use it in GitHub Desktop.
Autocleaning .deb based systems
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 | |
sudo aptitude update | |
sudo aptitude dist-upgrade | |
OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}') | |
CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g') | |
LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)" | |
METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)" | |
OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL) | |
BLUE="\033[1;33m" | |
RED="\033[0;31m" | |
ENDCOLOR="\033[0m" | |
if [ $USER != root ]; then | |
echo -e $RED"Error: must be root" | |
echo -e $BLUE"Exiting..."$ENDCOLOR | |
exit 0 | |
fi | |
echo -e $BLUE"Cleaning apt cache..."$ENDCOLOR | |
aptitude clean | |
echo -e $BLUE"Removing old config files..."$ENDCOLOR | |
sudo aptitude purge $OLDCONF | |
echo -e $BLUE"Removing old kernels..."$ENDCOLOR | |
sudo aptitude purge $OLDKERNELS | |
echo -e $BLUE"Emptying every trashes..."$ENDCOLOR | |
rm -rf /home/*/.local/share/Trash/*/** &> /dev/null | |
rm -rf /root/.local/share/Trash/*/** &> /dev/null | |
sudo aptitude update | |
echo -e $BLUE"Script Finished!"$ENDCOLOR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment