#!/usr/bin/env bash

echo "==> Remove all linux kernels except the current one"
dpkg --list | awk '{ print $2 }' | grep 'linux-image-4.*-generic' | grep -v $(uname -r) | xargs apt-get -y purge

apt-get -y autoremove --purge
apt-get -y autoclean
apt-get -y clean

dd if=/dev/zero of=/junk bs=1M
rm -f /junk

sync

#!/usr/bin/env bash

if type apt-get >/dev/null 2>&1; then
    apt-get clean
fi

if type yum >/dev/null 2>&1; then
    yum clean all
fi

dd if=/dev/zero of=/junk bs=1M
rm -f /junk

sync

--- 
+++ 
@@ -1,12 +1,11 @@
 #!/usr/bin/env bash
 
-if type apt-get >/dev/null 2>&1; then
-    apt-get clean
-fi
+echo "==> Remove all linux kernels except the current one"
+dpkg --list | awk '{ print $2 }' | grep 'linux-image-4.*-generic' | grep -v $(uname -r) | xargs apt-get -y purge
 
-if type yum >/dev/null 2>&1; then
-    yum clean all
-fi
+apt-get -y autoremove --purge
+apt-get -y autoclean
+apt-get -y clean
 
 dd if=/dev/zero of=/junk bs=1M
 rm -f /junk
Remove extra Linux kernels and ap-get autoremove autoclean clean
