debuntu-toolkit/cleanup.sh

35 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2015-10-22 08:38:55 -04:00
#!/bin/bash
2015-10-22 08:43:09 -04:00
# AUTHOR: Josh North
# EMAIL: josh.north@point808.com
# BRIEF: Quick and dirty script to clear disk space (log files, apt cache, etc).
# This is most useful if creating a machine template or preparing for backups.
# USAGE: Put this file in /usr/local/bin/cleanup.sh or wherever you prefer is ok.
# Make sure to chmod +x and make it executable. Run from command line at will,
# or call from a pre-backup script.
# SETTINGS:
# -------------------- NOTHING TO CHANGE BELOW THIS LINE --------------------
2015-10-22 08:38:55 -04:00
# Delete old config files
apt-get purge $(dpkg -l|grep "^rc"|awk '{print $2}')
# Clean cache
apt-get autoremove -y && apt-get clean
# Clean apt lists - this will force re-download on next apt-get update and may not be desired
rm -rf /var/lib/apt/lists
# Delete some documentation
find /usr/share/doc -depth -type f ! -name copyright|xargs rm -rf
find /usr/share/doc -empty|xargs rmdir || true
2016-06-01 12:28:33 -04:00
rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/* /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*
2015-10-22 08:38:55 -04:00
find /usr/share/doc | egrep "\.gz" | xargs rm -rf
find /usr/share/doc | egrep "\.pdf$" | xargs rm -rf
find /usr/share/doc | egrep "\.tex$" | xargs rm -rf
find /usr/share/doc | egrep "\copyright" | xargs rm -rf
# Delete excess locales - modify if you want something else kept around!
find /usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'en' |xargs rm -rf
# Delete old log files
logrotate -f /etc/logrotate.conf
2016-06-01 12:28:33 -04:00
find /var/log -type f -regex '.*/[^/]*.gz$' -delete && find /var/log -type f -regex '.*/[^/]*.[0-9]$' -delete
# Purge root and current user history
cat /dev/null > /root/.bash_history
cat /dev/null > ~/.bash_history
2015-10-22 08:38:55 -04:00
exit 0
# EOF