The following is what I found after googling:
dpkg --list 'linux-image-*' \
| perl -ane 'BEGIN { $r = `uname -r` or die; chomp $r } print $F[1], "\n" if $F[0] eq "ii" && $F[1] !~ /\Q$r\E\b/' \
| xargs -r aptitude purge -y
Could someone combine the above 3 lines into one? I find it easier to copy and paste a single line into a sudo command than three lines, one at a time.
For Hauke Laging: I have edited this original post to include the error message when I tried to copy the three split lines at once following the sudo command:
username@hostname:~$ sudo -i
[sudo] password for username:
root@hostname:~# dpkg --list 'linux-image-*' \
>
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
un linux-image-2. <none> (no description available)
un linux-image-2. <none> (no description available)
un linux-image-2. <none> (no description available)
un linux-image-2. <none> (no description available)
ii linux-image-3. 3.14.4-1~bpo amd64 Linux 3.14 for 64-bit PCs
ii linux-image-3. 3.2.57-3+deb amd64 Linux 3.2 for 64-bit PCs
ii linux-image-am 3.14+57~bpo7 amd64 Linux for 64-bit PCs (meta-packag
root@hostname:~# | perl -ane 'BEGIN { $r = `uname -r` or die; chomp $r } print $F[1], "\n" if $F[0] eq "ii" && $F[1] !~ /\Q$r\E\b/' \
-bash: syntax error near unexpected token `|'
root@hostname:~#
root@hostname:~# | xargs -r aptitude purge -y
xargsabove needs to run undersudo.sudo aptitude purge -y "~i ^linux-image ! -$(uname -r)\$"