Azitech

Azimout's Linux weblog

Script to automatically remove all but latest Linux kernel

leave a comment »

Here’s a bash script I wrote to automatically remove all but the latest installed Linux kernel.

I run it daily in a cron job.

#!/bin/bash

# find all vmlinuz files in /boot
# replace "/boot/vmlinuz" with "linux-image"
# sort and remove the last line
x=$(find /boot -name vmlinuz* -print | sed 's/\/boot\/vmlinuz/linux-image/' | sort | head -n -1)

# if there's more than one Linux kernel installed, remove all but the latest one
if [ ${#x} -ne 0 ]; then
 echo "removing" $x
 sudo apt-get purge $x
fi
Advertisements

Written by azimout

02/11/2014 at 19:10

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: