How to quickly remove all unused packages under Debian
This is a quick and dirty way of removing and purging unused packages under Debian. When doing package development I found myself doing a lot of dpkg --purge manually. This was tedious. Also to find all unused packages left behind from old package installations can be tricky to do manually. Luckily there is a nice tool called deborphan that locate these unreferenced packages automatically. apt-get install deborphan It is actually a two-step process to remove all unwanted old files. First we have to uninstall all orphaned packages given by deborphan and then do a purge of all remaining files. I have combined these two steps in a simple shell script. #!/bin/bash ORPHANS=`deborphan` if [ ! -z "$ORPHANS" ]; then dpkg --remove $ORPHANS fi PURGES=`dpkg --list | grep ^rc | awk '{ print $2; }'` if [ ! -z "$PURGES" ]; then dpkg --purge $PURGES fi I believe the script speaks for itself. Simple but effective.
by Wilson 2013-04-18 17:56 UTC
Not completely refered to this article, just want to congrat you for the great job! Your articles have helped me a lot in various ocasions! Thanks!


by Daniel 2013-05-07 10:42 UTC
Thank you! I'm really glad you found the information useful. I do my best to keep my writing clear and informative. There may not always be frequent updates but I try to make them count :)


by Tommi 2014-02-18 09:23 UTC
awk can do grep: grep ^rc | awk '{ print $2; }' better: awk '/^rc/{print $2}'


by Daniel 2014-02-19 06:11 UTC
Good point Tommi :-)


by Mark 2014-06-29 14:40 UTC
You can also try: deborphan --guess-all | xargs sudo aptitude purge -y Note that this can be performed repeatedly because of the way the dependencies work. Also, to take care of residual config (rc) files, just use sudo aptitude purge ~c


by jon 2017-09-22 20:21 UTC
how about sudo dpkg --purge `deborphan`


Write a comment

Name

E-mail (not visible)

Comment


Code from above