Find manually installed packages that has other packages depending on it on Debian based systems
Running command below generates a list of packages that can be marked as automatically installed, as long as apt-rdepends package were already installed. It generates a script that can be used to mark all found packages as manually installed.
echo \#\!/bin/bash > mark-auto.sh; apt-mark showmanual|xargs -I{} sh -c '[ "{}" = "$(apt-rdepends -r --state-follow=Installed --state-show=Installed {} 2>/dev/null)" ] || echo apt-mark auto {}' >> mark-auto.sh
It can be modified to mark packages automatically if preferred instead of writing to a script
apt-mark showmanual|xargs -I{} sh -c '[ "{}" = "$(apt-rdepends -r --state-follow=Installed --state-show=Installed {} 2>/dev/null)" ] || apt-mark auto {}'
Before running apt-get autoremove run it with pretend mode (-s), e.g
apt-get -s autoremove --purge
Mark any package not desired to be removed with
apt-mark manual <package>