Remove all kernels, but 2:
dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
You can edit /etc/yum.conf or /etc/dnf/dnf.conf and set installonly_limit to limit the amount of kernels installed:
installonly_limit=3
Remove all kernels, but 2:
dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
You can edit /etc/yum.conf or /etc/dnf/dnf.conf and set installonly_limit to limit the amount of kernels installed:
installonly_limit=3