Remove All Packages Marked as rc by DPKG

You can install packages using dpkg on Debian based systems such as Ubuntu. Dpkg is quite a useful command line tool. In addition to installing packages, dpkg also helps to remove packages and know the status of packages. While checking the status of packages using dpkg, you may come across the state rc.

What does rc mean?

rc corresponds to:

r: the package was marked for removal
c: the configuration files are currently present in the system
Click here for a full list

dpkg --list
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                              Version               Architecture          Description
ii  accountsservice                   0.6.40-2ubuntu11.3    amd64                 query and manipulate user account information
ii  acl                               2.2.52-3              amd64                 Access control list utilities

In nutshell, it means that the package is not completely removed. The configuration files are still present.
Let’s see all the packages marked as rc by dpkg:

dpkg --list |grep "^rc"

Let’s extract out the packages marked as rc:

dpkg --list |grep "^rc" | cut -d " " -f 3

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

dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
(Reading database ... 109335 files and directories currently installed.)
Removing letsencrypt (0.4.1-1) ...
Purging configuration files for letsencrypt (0.4.1-1) ...
Removing linux-image-4.4.0-92-generic (4.4.0-92.115) ...
Purging configuration files for linux-image-4.4.0-92-generic (4.4.0-92.115) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-92-generic /boot/vmlinuz-4.4.0-92-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-92-generic /boot/vmlinuz-4.4.0-92-generic
Removing linux-image-extra-4.4.0-92-generic (4.4.0-92.115) ...
Purging configuration files for linux-image-extra-4.4.0-92-generic (4.4.0-92.115) ...
Removing python-pbr (1.8.0-4ubuntu1) ...
Purging configuration files for python-pbr (1.8.0-4ubuntu1) ...

First letter -> desired package state (“selection state”):

  • u … unknown
  • i … install
  • r … remove/deinstall
  • p … purge (remove including config files)
  • h … hold

Second letter -> current package state:

  • n … not-installed
  • i … installed
  • c … config-files (only the config files are installed)
  • U … unpacked
  • F … half-configured (configuration failed for some reason)
  • h … half-installed (installation failed for some reason)
  • W … triggers-awaited (package is waiting for a trigger from another package)
  • t … triggers-pending (package has been triggered)

Third letter -> error state (you normally shouldn’t see a third letter, but a space, instead):

  • R … reinst-required (package broken, reinstallation required)

What is xargs and how does it work?

xargs command is designed to construct argument lists and invoke other utility. xargs reads items from the standard input or pipes, delimited by blanks or newlines, and executes the command one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored.

xargs functionality can be achieved using the backquote feature of shell. But, it offers more options. It can deal with blanks or special characters in file names easily. It is often used with find, grep and other commands.

xargs Examples

For example following example will print 1 2 3 4 using xargs (echo command is default)

echo 1 2 3 4 | xargs echo


echo 1 2 3 4 | xargs

You can force xargs to use at most max-args arguments per command line. For example following will use first two argument per command:

echo 1 2 3 4 | xargs -n 2

Find all .bak files in or below the current directory and delete them.

find . -name "*.bak" -type f -print | xargs /bin/rm -f

Source & credit to:

Disqus Comments Loading...

Recent Posts

Bittorrent IP Blocklists

In addition to using a VPN service, as an extra precaution I've been using the blocklist feature of my bittorrent… Read More

October 26, 2019 3:31 pm

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

June 7, 2019 3:44 pm

Change Grub Default Boot Entry on Linux Mint

I'm dual booting Windows and Linux Mint on my laptop. The grub default is to boot into Linux Mint, however… Read More

April 23, 2019 7:45 pm

How to Reset Secure Channel On Active Directory Domain Controller

When you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am

Run Systemd Script Before System Shutdown

I tried to retain the NGINX FastCGI cache and have it persist across system reboots instead of being ephemeral by… Read More

April 20, 2019 10:14 am

Learn Systemctl Usage to Manage Systemd Service in Linux

Systemd is new service manager for Linux. It's a replacement for all previous init systems (SysV/SysVinit & Ubuntu's Upstart) and… Read More

April 20, 2019 7:55 am