Skip to content

Instantly share code, notes, and snippets.

@RoverWire
Last active October 4, 2017 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoverWire/21daa3e768ab6b8d55b7 to your computer and use it in GitHub Desktop.
Save RoverWire/21daa3e768ab6b8d55b7 to your computer and use it in GitHub Desktop.
Server clean script
#!/bin/bash
#
# From openDesktop
# http://opendesktop.org/content/show.php/Ubucleaner?content=71529
YELLOW="\033[1;33m"
RED="\033[0;31m"
ENDCOLOR="\033[0m"
if [ "$USER" != root ]; then
echo -e $RED"Error: You must be root"$ENDCOLOR
echo -e $YELLOW"Exiting..."$ENDCOLOR
exit 0
fi
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)
echo -e $YELLOW"Removing old kernels..."$ENDCOLOR
apt purge $OLDKERNELS
echo -e $YELLOW"Remove unused packages..."$ENDCOLOR
apt autoremove
echo -e $YELLOW"Cleaning apt cache..."$ENDCOLOR
apt autoclean && apt clean
echo -e $YELLOW"Removing old config files..."$ENDCOLOR
sudo apt purge $OLDCONF
echo -e $YELLOW"Emptying trash..."$ENDCOLOR
rm -rf /home/*/.local/share/Trash/*/** &> /dev/null
rm -rf /root/.local/share/Trash/*/** &> /dev/null
echo -e $YELLOW"Script Finished!"$ENDCOLOR
df -h
#!/bin/bash
#
# Andrew Pennebaker
# 9 Mar 2011
#
# From openDesktop
# http://opendesktop.org/content/show.php/Ubucleaner?content=71529
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"Removing old kernels..."$ENDCOLOR
dpkg -l linux-* | \
awk '/^ii/{ print $2}' | \
grep -v -e `uname -r | cut -f1,2 -d"-"` | \
grep -e '[0-9]' | xargs sudo apt-get -y purge
apt-get autoremove
echo -e $YELLOW"Cleaning apt cache..."$ENDCOLOR
apt-get autoclean && apt-get clean
echo -e $YELLOW"Emptying trash..."$ENDCOLOR
rm -rf /home/*/.local/share/Trash/*/** &> /dev/null
rm -rf /root/.local/share/Trash/*/** &> /dev/null
echo -e $YELLOW"Script Finished!"$ENDCOLOR
df -h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment