Skip to content

Instantly share code, notes, and snippets.

@jonbrouse
Created April 20, 2017 01:58
Show Gist options
  • Save jonbrouse/4336bd14fe55dd522f24801581a65734 to your computer and use it in GitHub Desktop.
Save jonbrouse/4336bd14fe55dd522f24801581a65734 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Remove old kernels and clean up inode count.
[ "$(whoami)" = root ] || { echo "Please run this script as root" && exit 1; }
CURRENT_KERNEL=$(uname -r | sed s/-generic//g)
OLD_KERNEL_LIST=$(find /usr/src -maxdepth 1 -mindepth 1 -type d -not -name "*$CURRENT_KERNEL*" -exec basename {} \;)
echo -e "Current kernel: $(uname -r)\n"
echo -e "Old kernels: \n$OLD_KERNEL_LIST\n"
OLD_KERNELS=$(find /usr/src -maxdepth 1 -mindepth 1 -type d -not -name "*$CURRENT_KERNEL*" -exec basename {} \; | tr '\n' ' ')
echo "Removing old kernels..."
apt-get remove -y $OLD_KERNELS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment