Removing Debian packages which are upgradable and autoremovable

Keeping autoremovable packages is not very useful yet I tend to that because I always say my self “may be you’ll need it a day when you’ll have no network to reinstall it”. But upgrading autoremovable packages is even more useless. Here is how I remove them before running apt-get dist-upgrade.

sudo apt-get remove --purge $(comm -12 \
<(apt-get --dry-run dist-upgrade | grep -Po '^Inst \K[^ ]+' | sort) \
<(apt-get --dry-run autoremove | grep -Po '^Remv \K[^ ]+' | sort))

#apt, #debian