Skip to content

Instantly share code, notes, and snippets.

@poad
Last active November 13, 2017 03:22
Show Gist options
  • Save poad/5c574580a7c0ce91e88a30a09efe76f2 to your computer and use it in GitHub Desktop.
Save poad/5c574580a7c0ce91e88a30a09efe76f2 to your computer and use it in GitHub Desktop.
Ubuntuで最新のカーネル以外をアンインストールする ref: http://qiita.com/poad1010/items/388d6a020624a0c059c8
dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic"
$ dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic"
linux-image-4.8.0-36-generic
linux-image-4.8.0-51-generic
dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq
$ dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq
4.8.0-36
4.8.0-51
dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | sort -n -r | head -1
$ dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | sort -n -r | head -1
4.8.0-51
dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq |
$(dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | sort -n -r | head -1)
apt autoremove --purge -y linux-headers-<上記までで抽出した最新以外のバージョン>*
apt autoremove --purge -y linux-image-<上記までで抽出した最新以外のバージョン>*
USER=$(whoami)
if [ ! ${USER} = "root" ]
then
echo "Please use with sudo"
exit 1
fi
LATEST=$(dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | sort -n -r | head -1)
TARGETS=$(dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | grep -E -v ${LATEST})
for pkg_ver in ${TARGETS}
do
for pkg_prefix in linux-headers- linux-image-
do
apt autoremove --purge -y ${pkg_prefix}${pkg_ver}*
done
done
update-grub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment