3

I've found a bazillion references to get a list of the installed packages, but how can I print a single list of all known packages with their "package state" (not-installed, installed, half-installed etc. as defined by dpkg) in a shell, ideally like this:

awk   not-installed
bash  installed
cc    half-installed
[...]

dpkg --get-selections and dpkg --list only lists installed packages.

dpkg --get-selections '.' does not work.

apt-cache dump does not print whether packages are installed, and also prints a lot of irrelevant stuff.

I'm using Travis CI, which is running Ubuntu 12.04 LTS Server Edition 64 bit with for example dpkg-query 1.16.1.2.

6

2 Answers 2

1

You want dpkg-query;

For dpkg-query >= 1.17.11:

dpkg-query -f '${Package}\t${db:Status-Status}\n' -W '*'

For dpkg-query < 1.17.11:

dpkg-query -f '${Package} ${Status}\n' -W '*' | awk '{print $1"\t"$4}'

#1:

  • -f '${Package}\t${db:Status-Status}\n': When used with the -W option, specifies the format of the output (see man dpkg-query for other options);
  • -W '*': lists all the packages matching the pattern *;

#2:

  • -f '${Package} ${Status}\n': When used with the -W option, specifies the format of the output (see man dpkg-query for other options);
  • -W '*': lists all the packages matching the pattern *;
  • awk '{print $1"\t"$4}': prints only the first and fourth field;

In this case it seems like you want to list the status word, so I picked the db:Status-Status virtual field; here are the other virtual fields related to the package status:

              db:Status-Abbrev
                     It contains the abbreviated package status, such as  "ii"
                     (since dpkg 1.16.2).

              db:Status-Want
                     It contains the package wanted status, part of the Status
                     field (since dpkg 1.17.11).

              db:Status-Status
                     It contains the package status word, part of  the  Status
                     field (since dpkg 1.17.11).

              db:Status-Eflag
                     It  contains  the  package status error flag, part of the
                     Status field (since dpkg 1.17.11).

user@user-X550CL ~/tmp % dpkg-query -f '${Package}\t${db:status-status}\n' -W '*' | head
aalib1  not-installed
account-plugin-aim  installed
account-plugin-empathy  not-installed
account-plugin-facebook installed
account-plugin-flickr   installed
account-plugin-foursquare   not-installed
account-plugin-gadugadu not-installed
account-plugin-generic-oauth    not-installed
account-plugin-google   installed
account-plugin-groupwise    not-installed
4
  • 1
    @l0b0 Which version of dpkg-query?
    – kos
    Oct 3, 2015 at 17:58
  • Ah, I'm using an older dpkg-query. I've updated the question.
    – l0b0
    Oct 3, 2015 at 18:00
  • 1
    @l0b0 Try dpkg-query -f '${Package}\t${Status}\n' -W '*' | awk '{print $1"\t"$4}'
    – kos
    Oct 3, 2015 at 18:07
  • Changing db:Status-Status to Status worked. Thank you very much!
    – l0b0
    Oct 3, 2015 at 18:08
0
dpkg-query -l '*'

will show you all the installed, uninstalled and half installed packages. Just grep on the package you want to filter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .