Skip to content

Commit

Permalink
Create removeOldKernel.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mngugi committed Dec 18, 2024
1 parent 8585e4b commit b0ebca6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions removeOldKernel.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b0ebca6

Please sign in to comment.