Last active
November 11, 2022 09:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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