If you are an geeky user who keeps installing various software and updates then with the passage of time you will feel that your system is messed up. This is a shell script which lets you clean your system by removing the following:

apt cache

Config file for Uninstalled .deb packages

Unused Kernels

First lets discuss the different items which this script removes.

APT Cache

APT is the package management tool which is used to install/upgrade and remove packages in your Ubuntu system. If you use it often then it’s cache consumes a lot of space. By removing the apt cache you get plenty of free space.

Config Files For Uninstalled .Deb Packages

Suppose you downloaded a package for any software and it did not work. Many users forget to delete such packages. The Ubucleaner takes care of such packages and throws them out of the system.

Unused Kernel

There could be more than one kernel present in your system at the same time. But only one will be functional. This script gets rid of all unused kernels to free up system space and keep your system neat and clean.

SO, WHERE THE SCRIPT ???

here is it

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"

ENDCOLOR="\033[0m"

if [ $USER != root ]; then

echo -e $RED"Error: must be root"

echo -e $YELLOW"Exiting..."$ENDCOLOR

exit 0

fi

echo -e $YELLOW"Cleaning apt cache..."$ENDCOLOR

aptitude clean

echo -e $YELLOW"Removing old config files..."$ENDCOLOR

sudo aptitude purge $OLDCONF

echo -e $YELLOW"Removing old kernels..."$ENDCOLOR

sudo aptitude purge $OLDKERNELS

echo -e $YELLOW"Emptying every trashes..."$ENDCOLOR

rm -rf /home/*/.local/share/Trash/*/** &> /dev/null

rm -rf /root/.local/share/Trash/*/** &> /dev/null

echo -e $YELLOW"Script Finished!"$ENDCOLOR

#!/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" ENDCOLOR="\033[0m" if [ $USER != root ]; then echo -e $RED"Error: must be root" echo -e $YELLOW"Exiting..."$ENDCOLOR exit 0 fi echo -e $YELLOW"Cleaning apt cache..."$ENDCOLOR aptitude clean echo -e $YELLOW"Removing old config files..."$ENDCOLOR sudo aptitude purge $OLDCONF echo -e $YELLOW"Removing old kernels..."$ENDCOLOR sudo aptitude purge $OLDKERNELS echo -e $YELLOW"Emptying every trashes..."$ENDCOLOR rm -rf /home/*/.local/share/Trash/*/** &> /dev/null rm -rf /root/.local/share/Trash/*/** &> /dev/null echo -e $YELLOW"Script Finished!"$ENDCOLOR

open text editor, copy-paste code above, named to mintcleaner.sh and save it to your home folder

Then, open terminal, type

sudo chmod +x mintcleaner.sh

Now, run the script with the following command and it will take care of all things that mentioned above

sudo sh mintcleaner.sh

following my terminal log, show how it works

arboyz@DynaBook-Portege-2000 ~ $ sudo chmod +x mintcleaner.sh [sudo] password for arboyz: chmod: cannot access `mintcleaner.sh': No such file or directory arboyz@DynaBook-Portege-2000 ~ $ sudo chmod +x mintcleaner.sh arboyz@DynaBook-Portege-2000 ~ $ sudo sh mintcleaner.sh -e Cleaning apt cache... -e Removing old config files... No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 108 not upgraded. Need to get 0B of archives. After unpacking 0B will be used. -e Removing old kernels... No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 108 not upgraded. Need to get 0B of archives. After unpacking 0B will be used. -e Emptying every trashes... -e Script Finished! arboyz@DynaBook-Portege-2000 ~ $ sudo chmod +x mintcleaner.sh [sudo] password for arboyz: arboyz@DynaBook-Portege-2000 ~ $ sudo sh mintcleaner.sh -e Cleaning apt cache... -e Removing old config files... No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 108 not upgraded. Need to get 0B of archives. After unpacking 0B will be used. -e Removing old kernels... No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 108 not upgraded. Need to get 0B of archives. After unpacking 0B will be used. -e Emptying every trashes... -e Script Finished!

hope it useful for you