如何使用 dpkg-query 仅列出已安装的软件包版本?

如何使用 dpkg-query 仅列出已安装的软件包版本?

我正在使用dpkg-query -f '${Package}\n' -W "linux-image*"但它不仅仅显示已安装的内容。

答案1

打印状态,然后处理输出:

$ dpkg-query -f '${Package} ${Status}\n' -W "linux-image*"
linux-image unknown ok not-installed
linux-image-4.8.0-36-generic install ok installed
linux-image-4.8.0-51-generic install ok installed
linux-image-extra-4.8.0-36-generic install ok installed
linux-image-extra-4.8.0-51-generic install ok installed
linux-image-generic-hwe-16.04 install ok installed
$ dpkg-query -f '${Package} ${Status}\n' -W "linux-image*" | awk '$NF == "installed"{print $1}'
linux-image-4.8.0-36-generic
linux-image-4.8.0-51-generic
linux-image-extra-4.8.0-36-generic
linux-image-extra-4.8.0-51-generic
linux-image-generic-hwe-16.04

相关内容