-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup
executable file
·56 lines (42 loc) · 1.5 KB
/
cleanup
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
#!/usr/bin/env bash
function myclean {
## Show free space
df -Th | grep -v fs
# Will need English output for processing
LANG=en_GB.UTF-8
## Clean apt cache
apt-get update
apt-get -f install
apt-get -y autoremove
apt-get clean
## Remove old versions of snap packages
snap list --all | while read snapname ver rev trk pub notes; do
if [[ $notes = *disabled* ]]; then
snap remove "$snapname" --revision="$rev"
fi
done
## Set snap versions retain settings
if [[ $(snap get system refresh.retain) -ne 2 ]]; then snap set system refresh.retain=2; fi
rm -f /var/lib/snapd/cache/*
## Remove old versions of Linux Kernel
# This one-liner is deprecated since 18.04
# New 2 lines to remove old kernels
dpkg --list | grep 'linux-image' | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs apt-get -y purge
dpkg --list | grep 'linux-headers' | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs apt-get -y purge
## Rotate and delete old logs
/etc/cron.daily/logrotate
find /var/log -type f -iname *.gz -delete
journalctl --rotate
journalctl --vacuum-time=1s
apt autoremove
## Show free space
df -Th | grep -v fs
}
#prune docker
docker system prune --volumes -f
#conda clean
conda clean -a -y
#nextflow clean
nextflow clean -k -f
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
myclean