What do the various dpkg flags like 'ii' 'rc' mean?

I frequently need to check which packages are installed, and I use the following command:

dpkg -l | grep foo

which gives the following output

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                       Version         Description
ii   foo                       <version>         <description>
  1. What does the ii mean?
  2. What other flags are there?
  3. How to read the flags? (because the explanation is quite complicated, IMO)

Thanks.


Solution 1:

Where to find this information in the system

You can find this information out in the head of dpkg -l output, as it's just a formatting convention:

dpkg -l | head -3

Copied here for reference:

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)                    

Description of each field

As you can see from the first three lines:

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)

Solution 2:

The first letter displays what is the expected status of the package.
The second letter displays what is the current status of the package.

So for example:

ii means 'It should be installed and it is installed' whereas
rc means 'It's removed/uninstalled but it's configuration files are still there'

Solution 3:

Because my rep is low, I cannot comment to answer the questions people have about where to get this info. After reviewing source code for dpkg and related programs' main.c code, I found what I was looking for.

The info for reading the -l | --list output is in

man dpkg-query

and not in

man dpkg

dpkg is merely acting as the front-end in these instances