Skip to content

Instantly share code, notes, and snippets.

@gacyun
Last active December 6, 2021 08:03
Show Gist options
  • Select an option

  • Save gacyun/e7117e5a3b10553b49be28c719abb372 to your computer and use it in GitHub Desktop.

Select an option

Save gacyun/e7117e5a3b10553b49be28c719abb372 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Run this script with:
# bash <(curl -L -s https://gist.github.com/gacyun/e7117e5a3b10553b49be28c719abb372/raw/aws-ami-clean.sh)
function print_green {
echo -e "\e[32m${1}\e[0m"
}
function clean_package_cache {
which yum && {
yum clean all
return
}
which apt-get && {
apt-get -y autoremove
aptitude clean
aptitude autoclean
return
}
}
print_green 'clean yum cache'
clean_package_cache
print_green 'remove ssh keys'
[ -f /home/ec2-user/.ssh/authorized_keys ] && rm /home/ec2-user/.ssh/authorized_keys
print_green 'clean logs'
find /var/log -type f | while read f; do echo -ne '' > $f; done
print_green 'clean bash history'
unset HISTFILE
[ -f /root/.bash_history ] && rm /root/.bash_history
[ -f /home/ec2-user/.bash_history ] && rm /home/ec2-user/.bash_history
print_green 'ami clean finished!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment