Remove Old Unused Linux Kernels on Ubuntu

Remove Old Unused Linux Kernels on Ubuntu

Over time, as you regularly update the Ubuntu system, the old Linux kernels accumulate, taking up valuable disk space. While it's essential to keep the system updated for security and performance reasons, it's equally important to clean up the remnants of older versions of Linux kernels that are no longer in use. This tutorial demonstrates how to remove old unused Linux kernels on Ubuntu.

Run the following command to remove unused Linux kernel modules:

dpkg -l | grep linux-modules | awk '{ print $2 }' | sort -V | sed -n "/$(uname -r)/q;p" | xargs sudo apt purge --autoremove -y

This command lists all installed Linux kernel modules, sorts them in version order, excludes the currently running kernel, and then removes them using the APT package manager.

Next, run command to remove unused Linux kernel headers:

dpkg -l | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n "/$(uname -r)/q;p" | xargs sudo apt purge --autoremove -y

Similar to the previous command, this one targets the Linux kernel headers, ensuring that only the outdated ones are removed from the system.

Leave a Comment

Cancel reply

Your email address will not be published.