How to clean your Linux Mint system from old systemfiles, unused files, trash and old kernels.

How to clean your system from old systemfiles, trash and old kernels.

Found an excellent script on linuxmint.com for cleaning your system of unwanted files, I have updated the script to use APT instead of APTITUDE but you can also change this to your preference, here you can also find the script and the link to the original site.

First create a file, in terminal type 

nano cleanup

and cut and paste the following code into the file

#!/bin/bash

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)
YELLOW="\033[1;33m"
RED="\033[0;31m"
BLUE="\e[34m"
GREEN="\e[92m"
ENDCOLOR="\033[0m"
clear

if [ $USER != root ]; then
echo -e $BLUE"Linux Mint 18.x System cleanup script"$ENDCOLOR
echo -e $RED"Error: Please run this script as ROOT"
echo -e $YELLOW"Exiting."$ENDCOLOR
exit 0
fi

echo -e $BLUE"Linux Mint 18.x System cleanup script."$ENDCOLOR
echo " "
echo -e $YELLOW"Updating current pacgakes...in progress"$ENDCOLOR
apt update

echo -e $YELLOW"Cleaning apt cache...in progress"$ENDCOLOR
sudo apt autoclean
sudo apt autoremove
echo -e $GREEN"Completed."$ENDCOLOR

echo -e $YELLOW"Removing old config files...in progress"$ENDCOLOR
sudo apt purge $OLDCONF
echo -e $GREEN"Completed."$ENDCOLOR

echo -e $YELLOW"Removing old kernels...in progress"$ENDCOLOR
sudo apt purge $OLDKERNELS
echo -e $GREEN"Completed."$ENDCOLOR

echo -e $YELLOW"Emptying Trash folders...in progress"$ENDCOLOR
rm -rf /home/*/.local/share/Trash/*/** &> /dev/null
rm -rf /root/.local/share/Trash/*/** &> /dev/null
echo -e $GREEN"Completed."$ENDCOLOR
echo " "
echo -e $BLUE"System cleanup completed."$ENDCOLOR

Now we have to make it executable, so run the chmod command

chmod +x cleanup

and run it as sudo

sudo ./cleanup

Link to the original code can be found here :

https://community.linuxmint.com/tutorial/view/373