Skip to content

Instantly share code, notes, and snippets.

@mvrilo
Created March 17, 2018 15:15
Show Gist options
  • Save mvrilo/7f179ab20f02128d674af986ac953511 to your computer and use it in GitHub Desktop.
Save mvrilo/7f179ab20f02128d674af986ac953511 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
bytesToHuman() {
b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d ${S[$s]} of space was cleaned up :3"
}
# Ask for the administrator password upfront
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
oldAvailable=$(df / | tail -1 | awk '{print $4}')
echo 'Empty the Trash on all mounted volumes and the main HDD...'
sudo rm -rfv /Volumes/*/.Trashes &>/dev/null
sudo rm -rfv ~/.Trash &>/dev/null
echo 'Clear System Log Files...'
# sudo rm -rfv /private/var/log/asl/*.asl &>/dev/null
# sudo rm -rfv /Library/Logs/DiagnosticReports/* &>/dev/null
sudo rm -rfv /Library/Logs/Adobe/* &>/dev/null
rm -rfv ~/Library/Containers/com.apple.mail/Data/Library/Logs/Mail/* &>/dev/null
# rm -rfv ~/Library/Logs/CoreSimulator/* &>/dev/null
echo 'Clear Adobe Cache Files...'
sudo rm -rfv ~/Library/Application\ Support/Adobe/Common/Media\ Cache\ Files/* &>/dev/null
echo 'Cleanup iOS Applications...'
rm -rfv ~/Music/iTunes/iTunes\ Media/Mobile\ Applications/* &>/dev/null
echo 'Remove iOS Device Backups...'
rm -rfv ~/Library/Application\ Support/MobileSync/Backup/* &>/dev/null
echo 'Cleanup XCode Derived Data and Archives...'
rm -rfv ~/Library/Developer/Xcode/DerivedData/* &>/dev/null
rm -rfv ~/Library/Developer/Xcode/Archives/* &>/dev/null
echo 'Cleanup Homebrew Cache...'
brew cleanup --force -s &>/dev/null
brew cask cleanup &>/dev/null
rm -rfv /Library/Caches/Homebrew/* &>/dev/null
brew tap --repair &>/dev/null
echo 'Cleanup any old versions of gems'
gem cleanup &>/dev/null
echo 'Cleanup Docker <none> images'
docker rmi -f $(docker images -q --filter 'dangling=true')
echo 'Purge inactive memory...'
sudo purge
clear && echo 'Success!'
newAvailable=$(df / | tail -1 | awk '{print $4}')
count=$((newAvailable-oldAvailable))
count=$(( $count * 512))
bytesToHuman $count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment