Skip to content

Instantly share code, notes, and snippets.

@leonardobiffi
Created November 17, 2025 14:26
Show Gist options
  • Select an option

  • Save leonardobiffi/b5c9363fd85fc715782c0429f855894f to your computer and use it in GitHub Desktop.

Select an option

Save leonardobiffi/b5c9363fd85fc715782c0429f855894f to your computer and use it in GitHub Desktop.

Revisions

  1. leonardobiffi created this gist Nov 17, 2025.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/usr/bin/env bash
    echo ">> Current kernels:"
    rpm -qa kernel-core

    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"

    echo ">> Current kernels:"
    rpm -qa kernel-core
    exit 0