Last active
October 4, 2017 15:06
-
-
Save RoverWire/21daa3e768ab6b8d55b7 to your computer and use it in GitHub Desktop.
Server clean script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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