Last active
          August 26, 2025 07:36 
        
      - 
      
- 
        Save AbelVM/bd689cfddc9cc3bd3c3f909557de52b7 to your computer and use it in GitHub Desktop. 
    ubuntu free space script
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/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 sh -c '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. npm cache'$reset_color | |
| if ! command -v npm &> /dev/null | |
| then | |
| echo $fg_no_bold[yellow] 'There`s no node module installed via npm'$reset_color | |
| else | |
| index=$(npm cache verify | grep ^Index | grep -o "\w*$") | |
| if [ "$index" -eq "0" ]; | |
| then | |
| echo $fg_no_bold[yellow] 'npm cache is alredy empty'$reset_color | |
| else | |
| npm cache clean --force | |
| echo $fg_no_bold[yellow] "$index items deleted from npm cache"$reset_color | |
| fi; | |
| fi; | |
| echo '' | |
| echo $fg_no_bold[green] '10. Yarn cache'$reset_color | |
| if ! command -v yarn &> /dev/null | |
| then | |
| echo $fg_no_bold[yellow] 'There`s no nodejs module installed via yarn'$reset_color | |
| else | |
| yarn cache clean | |
| fi; | |
| echo '' | |
| echo $fg_no_bold[green] '11. UV cache'$reset_color | |
| if ! command -v uv &> /dev/null | |
| then | |
| echo $fg_no_bold[yellow] 'There`s no Python module installed via uv'$reset_color | |
| else | |
| uv cache prune && uv cache clean | |
| fi; | |
| echo '' | |
| echo '' | |
| echo $fg_bold[green] 'Root filesystem status'$reset_color | |
| df -h / | |
| echo '' | |
| echo $fg_bold[magenta] 'DONE'$reset_color | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment