Removes orphaned snap packages unless they are default providers or bases; also removes disabled snaps.
- The script uses
snap connectionsto find all snap packages that have no connections (i.e. are orphaned). - It filters out themes and slot-based connections.
- It extracts the package names from the output and stores them in the
orphanvariable. - It checks if any of the orphaned packages are default providers for other packages by parsing the
snap.yamlfiles. - If an orphaned package is a default provider, it will not be removed.
- Otherwise, the script will remove the orphaned package using elevated privileges (sudo/doas).
Install via Debian package:
sudo dpkg -i orphand-snaps_*.debThe installation:
- Creates the systemd service and weekly timer (automatically enabled)
- Prepares the state directory
/var/lib/orphand-snaps/for tracking removed snaps - Installs the man page
Once installed, a weekly timer runs the cleanup automatically every 7 days.
Run directly:
orphand-snapsWhen run as a non-root user, the script will use elevated privileges (sudo/doas) automatically.
To override the elevation method:
OVERRIDE_ELEVATION=doas orphand-snaps`
The last run records removed snaps to:
- State file:
/var/lib/orphand-snaps/last_removed.txt
List snaps removed in the last run:
orphand-snaps undoRestore a single snap:
orphand-snaps undo SNAPNAMERestore all snaps removed in the last run:
orphand-snaps undo allTo uninstall the package and clean up:
sudo apt remove orphand-snapsThis will:
- Disable and remove the systemd timer and service
- Keep the state file for reference (see
sudo dpkg --purge orphand-snapsto also remove it)
To completely remove all data:
sudo dpkg --purge orphand-snaps- Be careful when running this script, as it will permanently remove packages without prompting for confirmation.
- The script requires
snapdto be installed. - Elevated privileges (sudo or doas) are required for snap removal operations when running as a non-root user.