0

I used this command

echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo apt-get -y purge

from this link to remove old kernels to free up the disk space, but while executing that command I get the following message

...
1 upgraded, 2 newly installed, 2 to remove and 288 not upgraded.
Need to get 52.0 MB of archives.
After this operation, 186 kB of additional disk space will be used.
...

Shouldn't this command free up the disk space instead of using additional disk space ?

2 Answers2

2

Didn't you do:

echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs echo sudo apt-get -y purge
......................................................................................................................................................................................................................................................^^^^

first?

Seriously, use the /usr/bin/purge-old-kernels script (part of the byobu package)

waltinator
  • 36,399
0

Try this:

Open a terminal,

Press Ctrl+Alt+T

Run it:

exec sudo -i

CONFOLD=$(dpkg -l|grep "^rc"|awk '{print $2}')

KERNELCUR=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')

PKGLINUX="linux-(image|headers|ubuntu-modules|restricted-modules)"

PKGMETALINUX="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"

KERNELSOLD=$(dpkg -l|awk '{print $2}'|grep -E $PKGLINUX |grep -vE $PKGMETALINUX|grep -v $KERNELCUR)

apt-get purge $CONFOLD

apt-get purge $KERNELSOLD

apt-get autoremove

To free up more disk space you can continue running:

apt-get install --reinstall deborphan

deborphan

apt-get --purge remove $(deborphan)

deborphan --libdevel

apt-get --purge remove $(deborphan --libdevel)

deborphan --find-config

dpkg --purge $(deborphan --find-config)

apt-get autoremove

apt-get clean
kyodake
  • 15,401