Skip to content

Instantly share code, notes, and snippets.

@AbelVM
Last active September 4, 2023 11:48
Show Gist options
  • Save AbelVM/bd689cfddc9cc3bd3c3f909557de52b7 to your computer and use it in GitHub Desktop.
Save AbelVM/bd689cfddc9cc3bd3c3f909557de52b7 to your computer and use it in GitHub Desktop.
ubuntu free space script
#!/bin/zsh
autoload colors && colors
echo ''
echo $fg_bold[magenta] 'Let`s free some disk space...'$reset_color
echo ''
echo $fg_no_bold[green] '1. journal space'$reset_color
journalctl --disk-usage
echo ''
sudo journalctl --rotate
echo ''
sudo journalctl --vacuum-time=2d
echo ''
echo $fg_no_bold[green] '2. snap caché'$reset_color
if ! command -v snap &> /dev/null
then
echo $fg_no_bold[yellow] 'There`s no app installed via Snap'$reset_color
else
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
sudo snap remove "$snapname" --revision="$revision"
done
fi;
echo ''
echo $fg_no_bold[green] '3. apt cache, packages'$reset_color
sudo apt autoclean && sudo apt autoremove -y
echo ''
echo $fg_no_bold[green] '4. trash bin'$reset_color
if ! command -v gio &> /dev/null
then
echo $fg_no_bold[red] 'This only works in Gnome'$reset_color
else
echo "Trash size: $(du -sh $HOME/.local/share/Trash | awk '{print $1;}' )"
gio trash --empty
fi;
echo ''
echo $fg_no_bold[green] '5. Chrome cache'$reset_color
dir="/home/$USER/.cache/google-chrome"
if [ -d "$dir" -a ! -h "$dir" ]
then
echo "Reclaimed: $(du -sh "$dir" | awk '{print $1;}' )"
rm -rf "$dir"
else
echo $fg_no_bold[yellow] "Chrome cache was already empty"$reset_color
fi
echo ''
echo $fg_no_bold[green] '6. Firefox cache'$reset_color
dir="/home/$USER/.cache/mozilla/firefox/"
if [ -d "$dir" -a ! -h "$dir" ]
then
echo "Reclaimed: $(du -sh "$dir" | awk '{print $1;}' )"
rm -rf "$dir"
else
echo $fg_no_bold[yellow] "Firefox cache was already empty"$reset_color
fi
echo ''
echo $fg_no_bold[green] '7. Flatpak cache and leftovers'$reset_color
if ! command -v flatpak &> /dev/null
then
echo $fg_no_bold[yellow] 'There`s no app installed via Flatpack'$reset_color
else
sudo rm -rf /var/tmp/flatpak-cache-* 2> /dev/null
sudo flatpak uninstall --unused -y
fi;
echo ''
echo $fg_no_bold[green] '8. Pip cache'$reset_color
if ! command -v pip &> /dev/null
then
echo $fg_no_bold[yellow] 'There`s no Python module installed via pip'$reset_color
else
pip cache purge
fi;
echo ''
echo $fg_no_bold[green] '9. Yarn cache'$reset_color
if ! command -v yarn &> /dev/null
then
echo $fg_no_bold[yellow] 'There`s no Python module installed via pip'$reset_color
else
yarn cache clean
fi;
echo ''
echo $fg_bold[magenta] 'DONE'$reset_color
#echo '5. remove old WAL'
#TODO: psql -U postgres -tA -c "SHOW data_directory;"
#sudo docker exec -it postgis1233 pg_archivecleanup -d /var/lib/postgresql/data/pg_wal FFFFFFFFFFFFFFFFFFFFFFFF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment