-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanmac.sh
executable file
·93 lines (74 loc) · 2.61 KB
/
cleanmac.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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))
(( s++ ))
done
echo "$b$d ${S[$s]} of space was cleaned up"
}
# Ask for the administrator password upfront
sudo -v
# Keep-alive sudo until `clenaup.sh` has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
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
if type "brew" &>/dev/null; then
echo 'Update Homebrew Recipes...'
brew update
echo 'Upgrade and remove outdated formulae'
brew upgrade --cleanup
echo 'Cleanup Homebrew Cache...'
brew cleanup -s &>/dev/null
#brew cask cleanup &>/dev/null
rm -rfv $(brew --cache) &>/dev/null
brew tap --repair &>/dev/null
fi
if type "gem" &> /dev/null; then
echo 'Cleanup any old versions of gems'
gem cleanup &>/dev/null
fi
if type "docker" &> /dev/null; then
echo 'Cleanup Docker'
docker container prune -f
docker image prune -f
docker volume prune -f
docker network prune -f
fi
if [ "$PYENV_VIRTUALENV_CACHE_PATH" ]; then
echo 'Removing Pyenv-VirtualEnv Cache...'
rm -rfv $PYENV_VIRTUALENV_CACHE_PATH &>/dev/null
fi
if type "npm" &> /dev/null; then
echo 'Cleanup npm cache...'
npm cache clean --force
fi
if type "yarn" &> /dev/null; then
echo 'Cleanup Yarn Cache...'
yarn cache clean --force
fi
echo 'Purge inactive memory...'
sudo purge
echo 'Success!'
newAvailable=$(df / | tail -1 | awk '{print $4}')
count=$((oldAvailable - newAvailable))
#count=$(( $count * 512))
bytesToHuman $count