henrydenhengst

Ubuntu cleaner

Jun 30th, 2015
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.10 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. if [[ $EUID -ne 0 ]]; then
  4.    echo "This script must be run as root"
  5.    exit 1
  6. fi
  7. #
  8. apt-get -y install aptitude
  9. OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}')
  10. CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
  11. LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)"
  12. METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"
  13. OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL)
  14. YELLOW="\033[1;33m"
  15. RED="\033[0;31m"
  16. ENDCOLOR="\033[0m"
  17.  
  18. if [ $USER != root ]; then
  19.   echo -e $RED"Error: must be root"
  20.   echo -e $YELLOW"Exiting..."$ENDCOLOR
  21.   exit 0
  22. fi
  23.  
  24. echo -e $YELLOW"Cleaning apt cache..."$ENDCOLOR
  25. aptitude clean
  26.  
  27. echo -e $YELLOW"Removing old config files..."$ENDCOLOR
  28. sudo aptitude purge $OLDCONF
  29.  
  30. echo -e $YELLOW"Removing old kernels..."$ENDCOLOR
  31. sudo aptitude purge $OLDKERNELS
  32.  
  33. echo -e $YELLOW"Emptying every trashes..."$ENDCOLOR
  34. rm -rf /home/*/.local/share/Trash/*/** &> /dev/null
  35. rm -rf /root/.local/share/Trash/*/** &> /dev/null
  36.  
  37. echo -e $YELLOW"Script Finished!"$ENDCOLOR
Advertisement
Add Comment
Please, Sign In to add comment