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
Desired=Unknown/Install/Remove/Purge/Hold
| 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

OR

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: linuxprograms.wordpress.com

Share
Disqus Comments Loading...

Recent Posts

VMWare vSphere 6.7 ESXTOP Output Garbled

If your VMWare vSphere 6.x environment command output of esxtop looks like a bunch of garbled gibberish (it's actually CSV… Read More

February 28, 2019 7:39 pm 19:39

How To Run RoboCopy Backup in Parallel

From time to time Windows Admins will surprise you with band-aid and bubble gum scripts, that's entirely expected I think.… Read More

February 28, 2019 12:20 pm 12:20

Windows 10 GodMode - The Ultimate Administrator Shortcut

Have you ever wondered what life might be like if the Windows 10 OS somehow had a single folder that… Read More

February 28, 2019 7:58 am 07:58

Samsung Galaxy S9 G960/G965 Stock ROM Firmware Download

There could be any number of reasons for needing to flash manufacturer stock OEM firmware on a Samsung Galaxy S9… Read More

January 24, 2019 7:42 am 07:42

Output IP Address with ipconfig Findstr Ethernet Adapter

How many times have you entered  ipconfig /all at the command line to return a single IP address, then have to strain… Read More

January 20, 2019 12:39 am 00:39

AWS SES Assistance in Enterprise Market - A Must Read

Designing e-mail solutions on a large scale can be a complex and costly challenge for a business: you need to… Read More

December 25, 2018 4:01 pm 16:01