A collection of some apt options to clean up those pesky packages - the ones that install 1000 lib dependencies - that I tend to forget.

I don’t remember sources for this one. I believe I gathered from several articles as well as some trial and error.

apt purge / apt-get purge

# basic
sudo apt-get purge <pkg>
sudo apt-get autoremove
 
# you REALLY want to get rid of that package and its dependencies
sudo apt-get purge $(apt-cache depends <pkg> | awk '{ print 2}'| tr '\n' ' ')
 
# other tangential commands
sudo apt-get update
sudo apt-get check
sudo apt-get -f install
sudo apt-get autoclean

one-liner

# replace grep input with something that would identify the most recently installed package
echo $(sudo apt-history install | grep 2024-08-09 | cut -d ' ' -f 4 | cut -d ':' -f 1 | tr '\n' ' ')`

apt-history bash script dependency

  • install to /usr/local/bin or ~/.local/bin
#!/bin/bash
case "$1" in
install)
	cat /var/log/dpkg.log | grep 'install '
	;;
upgrade|remove)
	cat /var/log/dpkg.log | grep $1
	;;
rollback)
	cat /var/log/dpkg.log | grep upgrade | \
		grep "$2" -A10000000 | \
		grep "$3" -B10000000 | \
		awk '{print $4"="$5}'
	;;
)
	cat /var/log/dpkg.log
	;;
esac