-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathfree_space.sh
executable file
·74 lines (65 loc) · 3.45 KB
/
free_space.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
#!/usr/bin/env bash
# **************************************************************************** #
# #
# ::: :::::::: #
# free_space.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: aguiot-- <aguiot--@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/11/24 12:13:59 by aguiot-- #+# #+# #
# Updated: 2021/10/30 21:15:38 by aguiot-- ### ########.fr #
# #
# **************************************************************************** #
# Colors
blue=$'\033[0;34m'
cyan=$'\033[1;96m'
reset=$'\033[0;39m'
# Avoid boring prefix in du/df/etc
cd "$HOME"
initial_used_space=$(df -h "$HOME" | grep -v 'Filesystem' | awk '{ printf("%f", $3) }')
# Show current used space
initial_df=$(df -h . | grep --color=always -E "Size|Used|Avail|Capacity|[0-9]*\.*[0-9]*Mi|[0-9]*\.*[0-9]*Gi|[0-9]+\.*[0-9]+% |$")
echo -e "${blue}Current space:\n${reset}${initial_df}${reset}"
echo -e "${blue}\nHome folder:${reset}"
du -hd1 . 2>/dev/null | sort -h | grep --color=always "[0-9]*\.*[0-9]*M\t\|[0-9]*\.*[0-9]*G\t\|$"
echo ""
function delete() {
read -n1 -p "${blue}Delete ${cyan}$1${blue} ? [y/${cyan}N${blue}]${reset} " input
echo ""
if [ -n "$input" ] && [ "$input" = "y" ]; then
rm -rf "$1"
fi
}
# Delete heavy files/folders
delete "./Downloads/*"
delete "./.Trash/*"
delete "./.cache/*"
delete "./Library/Caches/*"
delete "./Library/Containers/com.docker.docker/*"
delete "./Library/Containers/*"
delete "./Library/Application Support/Code/User/*"
delete "./Library/Application Support/Code/Cache/*"
delete "./Library/Application Support/Code/CachedData/*"
delete "./Library/Application Support/Code/Crashpad/completed/*"
delete "./Library/Application Support/Code/User/workspaceStorage/*"
delete "./Library/Application Support/Slack/Cache/*"
delete "./Library/Application Support/Slack/Service Worker/CacheStorage/*"
delete "./Library/Application Support/discord/Cache/*"
delete "./Library/Application Support/discord/Code Cache/js/*"
delete "./Library/Application Support/discord/Crashpad/completed/*"
delete "./Library/Application Support/Google/Chrome/Default/Service\ Worker/CacheStorage/*"
delete "./Library/Application Support/Google/Chrome/Crashpad/completed/*"
delete "./Library/Developer/CoreSimulator/*"
# Brew cleanup
read -n1 -p "${blue}Cleanup Homebrew? (${cyan}brew cleanup${blue}) [y/${cyan}N${blue}]${reset} " input
echo ""
if [ -n "$input" ] && [ "$input" = "y" ]; then
brew cleanup ;:
fi
# Show before/after
echo -e "${blue}\nSpace before:\n${reset}${initial_df}${blue}\n\nSpace after:${reset}"
df -h . | grep --color=always -E "Size|Used|Avail|Capacity|[0-9]*\.*[0-9]*Mi|[0-9]*\.*[0-9]*Gi|[0-9]+\.*[0-9]+% |$"
final_used_space=$(df -h "$HOME" | grep -v 'Filesystem' | awk '{ printf("%f", $3) }')
freed_space=$(printf "%.1f" $(echo -e "${initial_used_space} - ${final_used_space}" | bc))
echo -e "${blue}\nFreed space: ${cyan}${freed_space}Gi${reset}"
echo -e "${blue}Pro tip: use ${cyan}GrandPerspective${blue} (GUI, available in the MSC) or ${cyan}ncdu${blue} (terminal, available with brew) to show a deep scan of your space.${reset}"