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.
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
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments