-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanMacCache
More file actions
executable file
·83 lines (71 loc) · 1.98 KB
/
Copy pathCleanMacCache
File metadata and controls
executable file
·83 lines (71 loc) · 1.98 KB
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
#!/bin/bash
# Clean Mac logs and caches
set -u
DRY_RUN=0
ASSUME_YES=0
for arg in "$@"; do
case "$arg" in
-n|--dry-run) DRY_RUN=1 ;;
-y|--yes) ASSUME_YES=1 ;;
-h|--help)
echo "usage: CleanMacCache [-n|--dry-run] [-y|--yes]"
exit 0
;;
*)
echo "unknown argument: $arg" >&2
exit 2
;;
esac
done
# Every removal goes through here so dry-run cannot be bypassed by adding a line below.
run() {
if [ "$DRY_RUN" -eq 1 ]; then
echo " would run: $*"
else
"$@"
fi
}
if [ "$DRY_RUN" -eq 0 ] && [ "$ASSUME_YES" -eq 0 ]; then
cat <<'WARN'
This deletes user and system caches and logs, including /var/log and
/private/var/folders. Deleted logs are not recoverable, and clearing
/private/var/folders while applications are running can destabilise them
until you reboot. Re-run with --dry-run to see the commands first.
WARN
printf 'Continue? [y/N] '
read -r reply
case "$reply" in
[yY]|[yY][eE][sS]) ;;
*) echo "Aborted."; exit 1 ;;
esac
fi
#user cache file
echo "cleaning user cache file from ~/Library/Caches"
run rm -rf ~/Library/Caches/*
#user logs
echo "cleaning user log file from ~/Library/Logs"
run rm -rf ~/Library/Logs/*
#system caches
echo "cleaning system caches"
run sudo rm -rf /Library/Caches/*
#system logs
echo "cleaning system logs from /Library/Logs"
run sudo rm -rf /Library/Logs/*
echo "cleaning system logs from /var/log"
run sudo rm -rf /var/log/*
echo "cleaning from /private/var/folders"
run sudo rm -rf /private/var/folders/*
#ios photo caches
echo "cleaning ios photo caches"
run rm -rf ~/Pictures/iPhoto\ Library/iPod\ Photo\ Cache/*
#application caches
echo "cleaning application caches"
for x in ~/Library/Containers/*/; do
echo "cleaning ${x}Data/Library/Caches/"
run rm -rf "${x}Data/Library/Caches/"*
done
# Cleaning up brew cache
echo "cleaning brew cache"
run brew cleanup
echo
echo "Cache cleanup process completed"