They offer different flash templates with latest features.
Login

Forgot password
Register
Back
Written by:
ratick
Score: 17
votes: 22
Format: Article

 Simple Script to Keep Up Your System Clean


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
 
If you found problem, please refer to the original source

Tags: System, Clean, Script, Simple, unused, cache
Created: 3 years ago.
Last edited: 3 years ago.
Reviewed: 3 years ago.
Read 907 times.

Comments
1 month ago

kilham
Worked well, Mint 16.  
2 months ago

cadavissr31
run this script if your using xbmchub on linux mint and see your buffers go up. Movies and shows run much better without as much stop and go.  
4 months ago

AlanWalker
Nice script! Good for studying scripts. There was a problem running it on my system however (LMDE-201403 (Cinnamon 64bit)).

A dialog box came up advising me that the script wanted to erase my boot image; when asked if I wanted to do that I said "NO".

The script finished executing and, after several boots and the exercise of several of my most often used applications, everything seems ok.

I'd "... refer to the original source." but that points to a generic Linux post some 3 years old now. The original poster probably has no particulars on Linux Mint.
 
5 months ago

atlantianking
Worked perfectly. My system needed to remove a few files and I ran it 3x and it ran straight through with nothing to report.
 
10 months ago

ratick
ourdeaux@lourdeaux-Pavilion-dv5000-EE393AV ~ $ sudo chmod +mintcleaner.sh
chmod: missing operand after `+mintcleaner.sh'
lourdeaux, your parameter is incorrect. the correct one must be $ sudo chmod +x mintcleaner.sh not
 
10 months ago

ratick
thanks for feedback all. glad if my article helpful  
10 months ago

penn07
Excellent Also works on Solydk Thank you.  
1 year ago

Stanley
Exactly what I was looking for! Thanks!  
1 year ago

rodeloli
Great job! This is exactly what I was looking for. kudos!  
1 year ago

lourdeaux
This didn't work with my text editor, Kate, in Mint 13 KDE. What next, please?
Lee
ourdeaux@lourdeaux-Pavilion-dv5000-EE393AV ~ $ sudo chmod +mintcleaner.sh
chmod: missing operand after `+mintcleaner.sh'
Try `chmod --help' for more information.
lourdeaux@lourdeaux-Pavilion-dv5000-EE393AV ~ $ chmod --help
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
or: chmod [OPTION]... OCTAL-MODE FILE...
or: chmod [OPTION]... --reference=RFILE FILE...
Change the mode of each FILE to MODE.

-c, --changes like verbose but report only when a change is made
--no-preserve-root do not treat `/' specially (the default)
--preserve-root fail to operate recursively on `/'
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
--reference=RFILE use RFILE's mode instead of MODE values
-R, --recursive change files and directories recursively
--help display this help and exit
--version output version information and exit

Each MODE is of the form `[ugoa]*([-+=]([rwxXst]*|[ugo]))+'.

Report chmod bugs to bug-coreutils@gnu.org
 
2 years ago

roht
very nice.  
2 years ago

Diogo_Almeida
Works as promised!  

Other tutorials from ratick