3

On Debian/Ubuntu, dpkg can show me packages, include the version and what's installed (e.g. dpkg -l postgresql\*). But that shows all packages that it knows about, whether installed or not.

Is it possible to make dpkg only show me the installed packages?

I've tried on dpkg v1.21.8 on Debian testing/bookworm, and v1.19.0.5 on Ubuntu 18.04 bionic

Amandasaurus
  • 31,471
  • 65
  • 192
  • 253
  • 4
    According to the man page `dpkg -l` **does** only show installed packages (and packages with residual config). I can confirm this behaviour on my Ubuntu 18.04 and 20.04 machines. – Gerald Schneider Jun 28 '22 at 11:22

2 Answers2

4

dpkg itself cannot do it, but it's possible to achieve it with a combination of dpkg-query and awk:

dpkg-query -W -f '${db:Status-Status} ${Package}\n' 'linux-image-[0-9]*' | awk '$1 != "not-installed" {print}'

See this question over on Ask Ubuntu: https://askubuntu.com/questions/1330078/limit-output-of-dpkg-query-w-to-installed-packages

Tilman Schmidt
  • 4,101
  • 12
  • 27
2
  1. dpkg -l command to list ALL installed Debian packages
  2. dpkg -l <pattern> | grep ^ii command to show installed packages for pattern

For example, if you want to list installed packages for gcc*

$ dpkg -l gcc*|grep ^ii
ii  gcc                             4:12.2.0-1   amd64        GNU C compiler
ii  gcc-10                          10.4.0-5     amd64        GNU C compiler
ii  gcc-10-base:amd64               10.4.0-5     amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-10-multilib                 10.4.0-5     amd64        GNU C compiler (multilib support)
ii  gcc-11                          11.3.0-5     amd64        GNU C compiler
ii  gcc-11-base:amd64               11.3.0-5     amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-11-multilib                 11.3.0-5     amd64        GNU C compiler (multilib support)
ii  gcc-12                          12.2.0-3     amd64        GNU C compiler
ii  gcc-12-base:amd64               12.2.0-3     amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-12-multilib                 12.2.0-3     amd64        GNU C compiler (multilib support)
ii  gcc-9-base:amd64                9.5.0-2+b1   amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-multilib                    4:12.2.0-1   amd64        GNU C compiler (multilib files)
lcheylus
  • 133
  • 1
  • 5