3 ms·
I tried it on Lubuntu 16.04; it required modification: # mystery one-liner from https://news.ycombinator.com/item?id=13513171 # dpkg -l 'linux-' | sed '/
by cagey 10y ago
I tried it on Lubuntu 16.04; it required modification:
# mystery one-liner from https://news.ycombinator.com/item?id=13513171
# dpkg -l 'linux-' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]\)./\1/;/[0-9]/!d' | xargs -p sudo apt-get -y purge
# my corrected/improved version:
noncurrent_kernel_pkgs() { dpkg -l 'linux-*[0-9]*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.\)-\([^0-9]\+\)/\1/")"'/d;s/^ii *\([^ ][^ ]*\)[^ ]*.*/\1/' ; }
# corrections/(possible-)improvements:
# - dpkg -l 'linux-' # returns nothing
# - dpkg -l 'linux-*[0-9]*' # moves 'pkgnm must contain a number' rule (last sed cmd in orig: '/[0-9]/!d') forward
# - pkgnm isolation/extraction was broken (did dpkg output change?)
output:
kg@kg-VirtualBox:~$ noncurrent_kernel_pkgs
linux-headers-4.4.0-43
linux-headers-4.4.0-43-generic
linux-headers-4.4.0-45
linux-headers-4.4.0-45-generic
linux-headers-4.4.0-53
linux-headers-4.4.0-53-generic
linux-headers-4.4.0-57
linux-headers-4.4.0-57-generic
linux-image-4.4.0-43-generic
linux-image-4.4.0-45-generic
linux-image-4.4.0-53-generic
linux-image-4.4.0-57-generic
linux-image-extra-4.4.0-43-generic
linux-image-extra-4.4.0-45-generic
linux-image-extra-4.4.0-53-generic
linux-image-extra-4.4.0-57-generic
kg@kg-VirtualBox:~$ uname -r
4.4.0-59-generic
kg@kg-VirtualBox:~$
- mianos 10y agoSorry about that, the '*' got removed from a non marked up paste. You are 100% correct. Just a little script to remove all but the current unused kernels that I use on 14.04. Yep, just take the xargs off to see what it will remove (which would always be good advice when pasting a random script LOL ).