This is an old revision of the document!
<code> current=$(lsb_release -cs)
for pkg in $(dpkg-query -W -f='${binary:Package}\n'); do
if ! apt-cache policy "$pkg" | grep -q "$current"; then
echo "$pkg"
apt autoremove --purge "$pkg"
fi
done <code>
For each package, select y or n to remove it and any dependencies.