Thursday, April 9, 2015

HOWTO Remove all Packages marked as "rc" by dpkg

Let’s see all the packages marked as rc by dpkg. The state "rc" means that the configuration files are not yet removed.

ximena@xdev:~$ dpkg -l |grep "^rc"
rc  apache2.2-common                       2.2.22-13+deb7u4               amd64        Apache HTTP Server common files
rc  libapache2-mod-php5                    5.4.36-0+deb7u3                amd64        server-side, HTML-embedded scripting language (Apache 2 module)
rc  libapr1                                1.4.6-3+deb7u1                 amd64        Apache Portable Runtime Library
rc  libaprutil1                            1.4.1-3                        amd64        Apache Portable Runtime Utility Library
rc  libgd2-noxpm:amd64                     2.0.36~rc1~dfsg-6.1            amd64        GD Graphics Library version 2 (without XPM support)
rc  libmozjs24d                            24.8.1esr-2~deb7u1             amd64        Mozilla SpiderMonkey JavaScript library
rc  libonig2                               5.9.1-1                        amd64        Oniguruma regular expressions library
rc  libqdbm14                              1.8.78-2                       amd64        QDBM Database Libraries without GDBM wrapper[runtime]
rc  libsensors4:amd64                      1:3.3.2-2+deb7u1               amd64        library to read temperature/voltage/fan sensors
rc  libsnmp-base                           5.4.3~dfsg-2.8+deb7u1          all          SNMP (Simple Network Management Protocol) MIBs and documentation
rc  libsnmp15                              5.4.3~dfsg-2.8+deb7u1          amd64        SNMP (Simple Network Management Protocol) library
rc  libvpx1:amd64                          1.1.0-1                        amd64        VP8 video codec (shared library)
rc  php5-cli                               5.4.36-0+deb7u3                amd64        command-line interpreter for the php5 scripting language
rc  php5-common                            5.4.36-0+deb7u3                amd64        Common files for packages built from the php5 source
rc  ssl-cert                               1.0.32                         all          simple debconf wrapper for OpenSSL
ximena@xdev:~$ 

Let’s extract out only the packages name marked as rc:

ximena@xdev:~$ dpkg -l |grep "^rc" | cut -d " " -f 3
apache2.2-common
libapache2-mod-php5
libapr1
libaprutil1
libgd2-noxpm:amd64
libmozjs24d
libonig2
libqdbm14
libsensors4:amd64
libsnmp-base
libsnmp15
libvpx1:amd64
php5-cli
php5-common
ssl-cert
ximena@xdev:~$ 

Now let’s remove all the packages marked as rc.

ximena@xdev:~$ dpkg -l |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
[sudo] password for ximena: 
(Reading database ... 44984 files and directories currently installed.)
Removing apache2.2-common ...
Purging configuration files for apache2.2-common ...
Removing libapache2-mod-php5 ...
Purging configuration files for libapache2-mod-php5 ...
Removing libapr1 ...
Purging configuration files for libapr1 ...
Removing libaprutil1 ...
Purging configuration files for libaprutil1 ...
Removing libgd2-noxpm:amd64 ...
Purging configuration files for libgd2-noxpm:amd64 ...
Removing libmozjs24d ...
Purging configuration files for libmozjs24d ...
Removing libonig2 ...
Purging configuration files for libonig2 ...
Removing libqdbm14 ...
Purging configuration files for libqdbm14 ...
Removing libsensors4:amd64 ...
Purging configuration files for libsensors4:amd64 ...
Removing libsnmp-base ...
Purging configuration files for libsnmp-base ...
Removing libsnmp15 ...
Purging configuration files for libsnmp15 ...
Removing libvpx1:amd64 ...
Purging configuration files for libvpx1:amd64 ...
Removing php5-cli ...
Purging configuration files for php5-cli ...
Removing php5-common ...
Purging configuration files for php5-common ...
Removing ssl-cert ...
Purging configuration files for ssl-cert ...
ximena@xdev:~$