-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean-diskspace.sh
More file actions
78 lines (62 loc) · 2.24 KB
/
clean-diskspace.sh
File metadata and controls
78 lines (62 loc) · 2.24 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
#!/usr/bin/env bash
# Delete superfluous storage-consuming directories and files and removes old packages.
#
# Usage:
#
# clean-diskspace.sh
#
# author: andreasl
set -x
# color codes
b='\e[1m' # bold
n='\e[m' # normal
# Empty Trash
dirsize=$(du -sh "$HOME/.local/share/Trash/" 2>/dev/null)
printf "${b}Info: $HOME/.local/share/Trash has the following size: ${dirsize}${n}\n"
rm -rfv "$HOME/.local/share/Trash/*"
# Gradle & related
dirsize=$(du -sh "$HOME/.gradle/caches" 2>/dev/null)
printf "${b}Info: $HOME/.gradle/caches has the following size: ${dirsize}${n}\n"
rm -rfv "$HOME/.gradle/caches"
dirsize=$(du -sh "$HOME/.gradle/daemon" 2>/dev/null)
printf "${b}Info: $HOME/.gradle/daemon has the following size: ${dirsize}${n}\n"
rm -rfv "$HOME/.gradle/daemon" # TODO verify
dirsize=$(du -sh "$HOME/.m2/repository" 2>/dev/null)
printf "${b}Info: $HOME/.m2/repository has the following size: ${dirsize}${n}\n"
rm -rfv "$HOME/.m2/repository"
find ~ -iname '.gradle' -type d -exec rm -rf '{}' \;
# Buildout
dirsize=$(du -sh "$HOME/.buildout/download-cache" 2>/dev/null)
printf "${b}Info: $HOME/.buildout/download-cache has the following size: ${dirsize}${n}\n"
rm -rfv "$HOME/.buildout/download-cache"
dirsize=$(du -sh "$HOME/.buildout/eggs" 2>/dev/null)
printf "${b}Info: $HOME/.buildout/eggs has the following size: ${dirsize}${n}\n"
rm -rfv "$HOME/.buildout/eggs"
# Brew
[ "$(command -v brew)" ] && brew cleanup -s
# Apt
if [ "$(command -v apt)" ]; then
sudo du -sh '/var/cache/apt/archives'
sudo apt clean
sudo apt autoremove --purge
sudo apt autoremove
fi
# Snap
if [ "$(command -v snap)" ]; then
# shellcheck disable=SC2162
LANG=C snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
fi
# dpkg
[ "$(command -v dpkg)" ] && sudo dpkg --purge --pending
# Docker
# Removes unused Docker data, unused images, stopped containers, unused networks, ...
[ "$(command -v docker)" ] && docker system prune --all --force
# Git
find ~ -type d -name '.git' -exec bash -c 'pushd "$1"; git gc; popd;' shell {} \;
# Python
find ~ -name "*.py[co]" -delete -or -name '__pycache__' -delete
# Jupyter
find ~ -name '.ipynb_checkpoints' -exec rm -rf '{}' \;