Skip to content

Instantly share code, notes, and snippets.

@saultools
Created January 23, 2026 13:18
Show Gist options
  • Select an option

  • Save saultools/39b29678d751ecccd9bdede7bcb683ee to your computer and use it in GitHub Desktop.

Select an option

Save saultools/39b29678d751ecccd9bdede7bcb683ee to your computer and use it in GitHub Desktop.
SNAP PACKAGES CHECKER - Includes all downloaded, installed and old (on disk but unistalled) ones. Inlcudes file size (space on disk used) and their location on your system.
#!/bin/bash
cat <<\EOF
.-./`) .---. .---. ____ ,---------. .-''-. .-'''-. ,---. .--. ____ .-------.
\ .-.') | | |_ _| .' __ `.\ \ .'_ _ \ / _ \| \ | | .' __ `. \ _(`)_ \
/ `-' \ | | ( ' ) / ' \ \`--. ,---'/ ( ` ) ' (`' )/`--'| , \ | |/ ' \ \| (_ o._)|
`-'`"` | '-(_{;}_)|___| / | | \ . (_ o _) | (_ o _). | |\_ \| ||___| / || (_,_) /
.---. | (_,_) _.-` | :_ _: | (_,_)___| (_,_). '. | _( )_\ | _.-` || '-.-'
| | | _ _--. | .' _ | (_I_) ' \ .---. .---. \ :| (_ o _) |.' _ || |
| | |( ' ) | | | _( )_ | (_(=)_) \ `-' / \ `-' || (_,_)\ || _( )_ || |
| | (_{;}_)| | \ (_ o _) / (_I_) \ / \ / | | | |\ (_ o _) // )
'---' '(_,_) '---' '.(_,_).' '---' `'-..-' `-...-' '--' '--' '.(_,_).' `--'
EOF
printf "%s\n"
# Function to list installed snaps with size, sorted from biggest to smallest
list_installed_snaps() {
echo "=== Installed Snaps (Sorted by Size) ==="
printf "%-20s %-15s %-10s %-20s %-15s %-10s\n" "Name" "Version" "Rev" "Tracking" "Publisher" "Size"
# Temporary file to store sorted snaps
temp_file=$(mktemp)
# Process snap list, calculate sizes, and sort
snap list | tail -n +2 | while read -r name version rev tracking publisher notes; do
# Get snap size in bytes for proper sorting
size_bytes=$(find /var/lib/snapd/snaps/ -type f -name "${name}_*.snap" -printf "%s\n" 2>/dev/null | head -1)
size_human=$(du -h /var/lib/snapd/snaps/${name}_*.snap 2>/dev/null | cut -f1)
# If no size found, use 0
size_bytes=${size_bytes:-0}
size_human=${size_human:-N/A}
# Store in temp file with sortable format
echo "$size_bytes $name $version $rev $tracking $publisher $size_human" >> "$temp_file"
done
# Sort by size (numeric sort, reverse order) and print
sort -rn "$temp_file" | while read -r size_bytes name version rev tracking publisher size_human; do
printf "%-20s %-15s %-10s %-20s %-15s %-10s\n" "$name" "$version" "$rev" "$tracking" "$publisher" "$size_human"
done
# Clean up temporary file
rm "$temp_file"
}
# Function to list downloaded snaps with size, sorted from biggest to smallest
list_downloaded_snaps() {
echo "=== Downloaded Snaps (Sorted by Size) ==="
printf "%-40s %-10s\n" "Snap File" "Size"
# Find all snap files, get their sizes, sort from biggest to smallest
find /var/lib/snapd/snaps/ -type f -name "*.snap" -print0 | xargs -0 du -b | sort -rn | while read -r size_bytes snap_path; do
filename=$(basename "$snap_path")
size_human=$(du -h "$snap_path" | cut -f1)
printf "%-40s %-10s\n" "$filename" "$size_human"
done
}
# Main script execution
if ! command -v snap &> /dev/null; then
echo "Snap is not installed on this system."
exit 1
fi
# Call functions
list_installed_snaps
list_downloaded_snaps
# Where to find your snaps
cat <<\EOF2
Downloaded Snaps Location: /var/lib/snapd/snaps
It would be a good idea to remove unused stuff from this folder...
EOF2
printf "%s\n"
# My github
printf "Script by \e]8;;https://github.com/saultools\e\\saul tools\e]8;;\e\\ on github \n"
printf "bye bye \n"
@saultools
Copy link
Author

saultools commented Jan 23, 2026

Output on an example system:
snap-checker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment