-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_cache_macos.sh
76 lines (71 loc) · 2.91 KB
/
remove_cache_macos.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
################################################################################
# @Author: carrgan
# @Date: 2020/03/16
# @Email: [email protected]
# @Filename: cache_cleaner_macos.sh
# @Last modified by: carrgan
# @Last modified time: 2020/03/16
# !/bin/bash
# Version: V0.1
# @Program:
# DEL Application Cache
################################################################################
function PrintDir(){
if [ -n "${2}" ]; then
for i in ${*}; do
raw=`echo ${i} | sed 's/[####][####]*/ /g'`
echo ${raw}
done
fi
}
function DelFile() {
if [ -n "${2}" ]; then
dir_f=`echo ${1} | sed 's/[---][---]*/\ /g'`
for i in ${*}; do
if [ ${i} != ${1} ]; then
raw=`echo ${i} | sed 's/[####][####]*/\ /g'`
rm -rf "$dir_f${raw}"
fi
done
fi
}
if [ -n "$1" ]; then
# Replace spaces with #### and --- and _
Pre=`ls /Users/carrgan/Library/Preferences/ | grep $1 | sed 's/[ ][ ]*/####/g'`
Support=`ls /Users/carrgan/Library/Application\ Support/ | grep $1 | sed 's/[ ][ ]*/####/g'`
CrashReporter=`ls /Users/carrgan/Library/Application\ Support/CrashReporter/ | grep $1 | sed 's/[ ][ ]*/####/g'`
Containers=`ls /Users/carrgan/Library/Containers/ | grep $1 | sed 's/[ ][ ]*/####/g'`
State=`ls /Users/carrgan/Library/Saved\ Application\ State/ | grep $1 | sed 's/[ ][ ]*/####/g'`
Caches=`ls /Users/carrgan/Library/Caches/ | grep $1 | sed 's/[ ][ ]*/####/g'`
Containers=`ls /Users/carrgan/Library/Containers/ | grep $1 | sed 's/[ ][ ]*/####/g'`
Logs=`ls /Users/carrgan/Library/Logs/ | grep $1 | sed 's/[ ][ ]*/####/g'`
PrintDir /Users/carrgan/Library/Preferences/: ${Pre}
PrintDir /Users/carrgan/Library/Application_Support/: ${Support}
PrintDir /Users/carrgan/Library/Containers/: ${Containers}
PrintDir /Users/carrgan/Library/Application_Support/CrashReporter/: ${CrashReporter}
PrintDir //Users/carrgan/Library/Saved_Application_State/: $State
PrintDir /Users/carrgan/Library/Caches/: $Caches
PrintDir /Users/carrgan/Library/Containers/: $Containers
PrintDir /Users/carrgan/Library/Logs/: $Logs
if [ -n "$Pre" ] || [ -n "$Support" ] || [ -n "$CrashReporter" ] ||
[ -n "$Containers" ] || [ -n "$State" ] || [ -n "$Cache" ] ||
[ -n "$Containers" ]|| [ -n "$Logs" ]; then
read -p "Do you want to del? y/n: " y_n
if [ ${y_n} == y ] || [ ${y_n} == Y ]; then
DelFile "/Users/carrgan/Library/Preferences/" ${Pre}
DelFile "/Users/carrgan/Library/Application---Support/" ${Support}
DelFile "/Users/carrgan/Library/Containers/" ${Containers}
DelFile "/Users/carrgan/Library/Application---Support/CrashReporter/" ${CrashReporter}
DelFile "/Users/carrgan/Library/Saved---Application---State/" $State
DelFile "/Users/carrgan/Library/Caches/" $Caches
DelFile "/Users/carrgan/Library/Containers/" $Containers
DelFile "/Users/carrgan/Library/Logs/" $Logs
else
echo "Did Nothing."
fi
else
echo "No Cache."
fi
else
echo "You need to enter a parameter!"
fi