clean system script.sh

jgirona
  12 years ago
  5

#!/bin/bash

OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}')
YELLOW="\\033[1;33m"
RED="\\033[0;31m"
ENDCOLOR="\\033[0m"

if [ $USER != root ]; then
echo -e $RED"Error: debes ser root"
echo -e $YELLOW"Hasta luego luca..."$ENDCOLOR
exit 0
fi

echo -e $YELLOW"Limpiando cache apt..."$ENDCOLOR
aptitude clean

echo -e $YELLOW"Eliminando viejas configuraciones..."$ENDCOLOR
sudo aptitude purge $OLDCONF


echo -e $YELLOW"Vaciando papeleras..."$ENDCOLOR
rm -rf /home/*/.local/share/Trash/*/** &> /dev/null
rm -rf /root/.local/share/Trash/*/** &> /dev/null

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

 

________________________________________________________

open gedit, paste the script ( bold text ) and save as script.sh ... and give execute permissions.

open terminal as root, go up script.sh and run as follows:

#. / script.sh

___________________________________________________________

4 variables declared in the first search for packages with a particular pattern, to see which have been uninstalled previously.
the other 3 variables are set to print to the console results.

2 º if you are not root, the script ends.

3 º erase the cache apt.

4 º delete configuration files of uninstalled programs.

5 º delete all the trash

6 th script ends

Comments
blueXrider 12 years ago

It might be safer for the beginner to use Ubuntu Tweak, Ailurus or Bleach Bit.

This needs to be modified, ie:
The script for English.

This is one I like

#!/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


dagon 12 years ago

Checklist:
-Remove things (allways fun)
-Printing messages in "colour" (allways fun)

Asking me to do the above mentioned things while being root? Promoted!
As @kazztan0325 says. You have some explaining to do.

:)


kazztan0325 12 years ago

I think, This tutorial would need to add explanation "what in system does this script clean", otherwise it would look like 'Spell of Magic' for Linux Beginners.

I don't understand this script too.