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
|
|
|
|
rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/*
|
|
|
|
rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*
|
|
|
|
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
|
|
|
|
find /var/log -type f -regex '.*/[^/]*.gz$' -delete && find /var/log -type f -regex '.*/[^/]*.[0-9]$' -delete
|
|
|
|
exit 0
|
|
|
|
# EOF
|