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