所有软件包的可排序列表 (dpkg)

gue*_*tli 1 dpkg etckeeper

我想转储使用dpkg.

到现在为止我都使用dpkg -l.

但它有一个缺点:对结果进行排序没有意义。

头:

root@aptguettler:~# LANG=C dpkg-query -l| sort | head
+++-===========================================================-=================================================-============-================================================================================
Desired=Unknown/Install/Remove/Purge/Hold
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
ii  a11y-profile-manager-indicator                              0.1.10-0ubuntu3                                   amd64        Accessibility Profile Manager - Unity desktop indicator
Run Code Online (Sandbox Code Playgroud)

尾巴:

root@aptguettler:~# LANG=C dpkg-query -l| sort | tail
rc  texlive-publishers-doc                                      2015.20160320-1                                   all          TeX Live: Documentation files for texlive-publishers
rc  texlive-science                                             2015.20160320-1                                   all          TeX Live: Natural and computer sciences
rc  texlive-science-doc                                         2015.20160320-1                                   all          TeX Live: Documentation files for texlive-science
rc  tpconfig                                                    3.1.3-15                                          amd64        touchpad device configuration utility
rc  ttf-indic-fonts-core                                        1:0.5.14ubuntu1                                   all          Core collection of free fonts for languages of India
rc  ttf-punjabi-fonts                                           1:0.5.14ubuntu1                                   all          Free TrueType fonts for the Punjabi language
rc  unity-lens-friends                                          0.1.3+14.04.20140317-0ubuntu1                     amd64        Friends scope for unity
rc  webaccounts-extension-common                                0.5-0ubuntu2.14.04.1                              amd64        Ubuntu Online Accounts browser extension - common files
rc  xfonts-mathml                                               6ubuntu1                                          all          Type1 Symbol font for MathML
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
Run Code Online (Sandbox Code Playgroud)

etckeeper我通过(相关问题与答案日志 hwinfo 输出与 etckeeper )保留此输出的历史记录。

我想改进的地方如下:

  • ascii-art 的线条不太好。应将其删除。
  • 前两个字符(例如ii)应删除或出现在末尾。

在基于 rpm 的系统上rpm -qa正是我所需要的。

Bro*_*oco 6

尝试

dpkg --get-selections | grep -v deinstall
Run Code Online (Sandbox Code Playgroud)

如果您需要输出中数据包的确切版本,您可以执行以下操作:

dpkg -l | grep '^ii' | awk '{print $2 "\t" $3}'
Run Code Online (Sandbox Code Playgroud)

这仅打印第 2 列和第 3 列。这也仅列出已安装的软件包,不列出已卸载的软件包或其他软件包。

编辑:另一个选项是 dpkg-query:

dpkg-query --show --showformat='${Package} ${Version}  ${Architecture} ${db:Status-Abbrev} \n'
Run Code Online (Sandbox Code Playgroud)

其中 --showformat (或 -f)定义要显示的列,在本例中为包名称、版本和体系结构以及末尾的短状态(例如“ii”和“rc”),即“\n”是换行符。

顺便说一下,“ii”定义了已安装的软件包,“rc”是未安装的软件包,这就是为什么我使用 grep 和 awk 来过滤未安装的软件包。

如果您喜欢,也可以添加列宽,如下所示:

dpkg-query --show --showformat='${Package;-50} ${Version;-40}  ${Architecture;-5} ${db:Status-Abbrev} \n'
Run Code Online (Sandbox Code Playgroud)

负的列宽表示方向为左,正的表示方向为右。

但要小心,如果宽度小于包名称中的字符数,包名称将被缩短。

我不太确定您需要该列表的目的。如果您只想拥有一个易于阅读的列表,那么 awk 或其他命令没有任何问题,如果您想将软件“备份”安装在另一台机器上,dpkg --get-selections(无需任何管道)就是这样的方法去,参见https://wiki.debian.org/ListInstalledPackages