From b0ebca67a732466ec804bcfeb7dd8d5de1f8140a Mon Sep 17 00:00:00 2001 From: "M.Ngugi" Date: Wed, 18 Dec 2024 19:37:40 +0300 Subject: [PATCH] Create removeOldKernel.sh --- removeOldKernel.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 removeOldKernel.sh diff --git a/removeOldKernel.sh b/removeOldKernel.sh new file mode 100755 index 0000000..7313c25 --- /dev/null +++ b/removeOldKernel.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Script to remove old kernels on Ubuntu/Debian or Fedora-based systems + +# Detect the current distribution +if [ -f /etc/debian_version ]; then + echo "Detected Debian/Ubuntu-based system." + echo "Removing old kernels except for the currently running one..." + sudo apt-get autoremove --purge -y +elif [ -f /etc/fedora-release ] || [ -f /etc/redhat-release ]; then + echo "Detected Fedora/RedHat-based system." + echo "Removing old kernels except for the latest two..." + sudo dnf remove $(dnf repoquery --installonly --latest-limit=2 -q) -y +else + echo "Unsupported distribution. Exiting." + exit 1 +fi +