Skip to content

Purge all packages

Published on: October 29, 2006 | Last modified on: August 19, 2011

If you happen to *remove* packages with apt-get or aptitude, there are still fragments of these packages on your system (configuration files etc.). If you want to *purge* a package (ie. remove all the files), you should use:

apt-get --purge remove <package>

or

aptitude purge <package>

I wrote the following script to purge the packages that were removed, but not purged:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
#
# This script purges all the packages that have a status different from ii
# 2005 - Julien Valroff <julien@kirya.net>
#
# Changelog:
#  0.01 (16/06/2005)
#   * Initial release
#  0.02 (16/10/2005)
#   * Fixed possible symlink attacks (uses mktemp)
#   * Updated regexp
#  0.03 (27/11/2005)
#   * Simplified usage (no question asked)
 
 
TMPFILE=`mktemp` || exit 1
dpkg -l | grep -v '^ii ' | awk '{print $2}' > $TMPFILE
 
count=$(cat $TMPFILE|wc -l)
count=$(expr $count - 5)
 
if [ $count -eq 0 ]; then
   echo "No package to purge."
else
    var=$(dpkg -l | grep -v '^ii ' | awk '{print $2}' | tail -n $count)
    sudo aptitude purge $var
fi
 
rm -f $TMPFILE

As usual, take care when using this kind of scripts!

UPDATE: aptitude just deals with this automatically with aptitude purge ~c