5 ms·
I used to use this to clean boot. dpkg -l 'linux-' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]\)./\1/;/[0-9]/!d' |
by mianos 10y ago
I used to use this to clean boot.
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
- pacifika 10y agoWhat does it do?
- alyandon 10y agoTake off the xargs part of the command and run it to see. :-D Just looking at it though, it looks like it'll purge kernel packages that are the currently booted one. I don't have a system handy to check though so take that with a grain of salt.
- alyandon 10y agoJust for posterity that should have been "are not the currently booted one".
- cagey 10y agoI 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 ).