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 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


OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}')
CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL)

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

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

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

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

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

echo -e $YELLOW"Emptying Trash 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 :