Skip to content

Instantly share code, notes, and snippets.

@olivertappin
Last active March 30, 2019 22:37
Show Gist options
  • Select an option

  • Save olivertappin/1628438fbb9460743a9021cddd7221ce to your computer and use it in GitHub Desktop.

Select an option

Save olivertappin/1628438fbb9460743a9021cddd7221ce to your computer and use it in GitHub Desktop.
Remove unused headers on Ubuntu
#!/bin/sh
# Run the following command to run this script locally:
# sh -c "$(curl -sSL https://gist.github.com/olivertappin/1628438fbb9460743a9021cddd7221ce/raw)"
headers=$(dpkg --list | grep -E 'linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+[0-9]+-generic' | awk {'print $2'} | grep -v `uname -r`)
echo "Current header: "
uname -r
echo ""
echo "Found the following unused headers:"
for header in $headers
do
echo $header;
done
echo ""
echo "This program will remove the unused headers listed above."
read -p "Do you want to continue? [Y/n]" REPLY
echo ""
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]
then
for header in $headers
do
sudo apt-get purge -y $header
done
echo "Complete. Consider running `sudo apt autoremove` to remove unused headers from disk."
else
echo "Not sure why you asked in the first place then... bye.";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment