I am using:
dpkg-query -W -f='${package}\t${version}\t${architecture}\n'
to list installed packages but it also shows packages marked for removal i.e. with status rc.
How do I get only installed packages?
I am using:
dpkg-query -W -f='${package}\t${version}\t${architecture}\n'
to list installed packages but it also shows packages marked for removal i.e. with status rc.
How do I get only installed packages?
The command that you are using only specifies the package, version number, and architecture and will print it all regardless of the status.
If you just want to show packages that are installed:
dpkg --list | grep ^ii
The status will be in the first column with ii meaning that it is expected to be and is installed. The pipe into grep ^ii shows only the packages with that status.
If you just want the installed packages with the amd64 architecture:
dpkg --list | grep "^ii.*amd64"
That will only print the the packages that contain the ii status and amd64.
To do the same using awk to only print the lines where the first column has ii and the fourth had amd64:
dpkg --list | awk '$1=="ii" && $4=="amd64"'
dpkg-query doesn’t support filtering on status, but it can output packages’ status, which allows them to be filtered:
dpkg-query -W -f='${Status}\t${package}\t${version}\t${architecture}\n' | grep "^install ok installed"
dpkg -l is based on dpkg-query and thus can’t filter on status itself either.
aptitude provides more powerful search options, and can be used for this; see Right way to get the list of installed packages matching a pattern? for details. The following command will display the package name, version, and architecture of all installed packages (and only installed packages):
aptitude search "~i" -F "%p%v#%E"
Note that the package name will include the architecture if it doesn’t match the system’s main architecture; for example
zlib1g 1:1.2.11.dfsg-1 amd64
zlib1g:i386 1:1.2.11.dfsg-1 i386