-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanhouse.sh
executable file
·75 lines (62 loc) · 2.18 KB
/
cleanhouse.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
#!/bin/bash
# Load helper functions
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`
source $SCRIPTPATH/helper_functions.sh
# Show disk usage before
colorprintf blue "\n --Before--\n"
df -h --total
printf "\nWe are now going to clean some shit up...\n"
# echo "Cleaning up old files in /var..."
# sudo find /var/* -atime +30 | wc -l
# sudo find /var/* -atime +30 -delete
if command -v rvm >/dev/null 2>&1; then
colorprintf orange "\nRunning rvm cleanup all...\n"
rvm cleanup all
fi
if command -v nvm >/dev/null 2>&1; then
colorprintf orange "\nRunning nvm cache clear...\n"
nvm cache clear
fi
if command -v apt >/dev/null 2>&1; then
colorprintf orange "\nRunning apt autoremove and autoclean...\n"
sudo apt -y autoremove
sudo apt -y autoclean
sudo apt -y clean
colorprintf orange "\nRemoving residual config files...\n"
sudo dpkg --purge $(dpkg --get-selections | grep deinstall | cut -f1)
elif command -v pacman >/dev/null 2>&1; then
colorprintf orange "\nCleaning up Pacman cache...\n"
sudo paccache -r
sudo paccache -ru
if [ -d $HOME/.cache/pikaur/pkg ]; then
paccache -rk2 --cachedir=$HOME/.cache/pikaur/pkg
paccache -ruk2 --cachedir=$HOME/.cache/pikaur/pkg
fi
fi
if command -v flatpak >/dev/null 2>&1; then
colorprintf orange "\nRemoving unused flatpak packages...\n"
flatpak uninstall --unused -y
fi
# printf "Cleaning up config, cache, and share files in the home directory...\n"
# find ~/.config/* -atime +90 | wc -l
# find ~/.config/* -atime +90 -delete
# find ~/.cache/* -atime +90 | wc -l
# find ~/.cache/* -atime +90 -delete
# find ~/.local/share/* -atime +90 | wc -l
# find ~/.local/share/* -atime +90 -delete
if command -v docker &>/dev/null; then
colorprintf orange "\nRunning docker prune....\n"
docker system prune
fi
colorprintf orange "\nRemoving broken symlinks...\n"
find ~/. -type l -! -exec test -e {} \; -print | wc -l
find ~/. -type l -! -exec test -e {} \; -delete
colorprintf orange "\nRemoving all but the last 30 days of journal logs...\n"
sudo journalctl --vacuum-time=30d
colorprintf orange "\nTaking out the trash...\n"
trash-empty
# Show disk usage after
colorprintf blue "\n --After--\n"
df -h --total
colorprintf green "\nAll done here!\n"