Skip to content

Instantly share code, notes, and snippets.

@vi7
Last active November 11, 2022 09:37
Show Gist options
  • Save vi7/5789f27b1bd90e7f4394a7664bc9d9c7 to your computer and use it in GitHub Desktop.
Save vi7/5789f27b1bd90e7f4394a7664bc9d9c7 to your computer and use it in GitHub Desktop.
Script that retains the latest kernel and removes old kernels if any. DNF compatible
#!/usr/bin/env bash
old_kernels=($(dnf repoquery --installonly --latest-limit=-1 -q))
if [ "${#old_kernels[@]}" -eq 0 ]; then
echo "No old kernels found"
exit 0
fi
if ! dnf remove "${old_kernels[@]}"; then
echo "Failed to remove old kernels"
exit 1
fi
echo "Removed old kernels"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment