Sek*_*mty 2 linux package-management kubuntu packages ubuntu
我正在使用 Kubuntu。我想获得系统上已安装软件包的列表,特别是让它们按类别排序,即在 Muon 软件包管理器中的类别过滤器选项卡中看到。作为视觉参考,它位于下图中窗口的左侧。
从 Muon 内部,有一个选项可以在 File 菜单中导出已安装的软件包列表,但它只是导出一个普通列表(我认为它执行dpkg --get-selections
命令),这不是我要找的。
我试图在该男子页看dpkg
,dpkg-query
,apt
和apt-get
,但我没有发现任何有用的信息。
我得到的唯一线索是手册dpkg-query
说明可以使用一些命令选项对输出进行排序,但我还没有找到如何按类别排序。
有什么线索吗?
您确实可以使用dpkg-query
和其他一些工具来做到这一点:
dpkg-query -Wf='${package}\t${Section}\t${status}\n' | grep installed |
gawk '{print $2"\t"$1}' | sort
Run Code Online (Sandbox Code Playgroud)
解释:
dpkg-query -Wf='${package}\t${section}\t${status}\n'
:此命令将列出所有包 ( -W
),如package name
< TAB > package section
< TAB > package status
。从dpkg-query
手册页:
-f, --showformat=format
This option is used to specify the format of the output --show
will produce. The format is a string that will be output for each package
listed.
Run Code Online (Sandbox Code Playgroud)
因此,仅此命令就会产生如下输出:
$ dpkg-query -Wf='${package}\t${Section}\t${status}\n' | head
a2ps text install ok installed
abiword editors install ok installed
abiword-common editors install ok installed
abiword-plugin-grammar editors install ok installed
abiword-plugin-mathview editors install ok installed
accountsservice admin install ok installed
acl utils install ok installed
acpi utils install ok installed
acpi-support-base admin install ok installed
acpid admin install ok installed
Run Code Online (Sandbox Code Playgroud)grep installed
: 只选择那些描述状态为 的包的行installed
。
gawk '{print $2"\t"$1}'
: 使用gawk只打印我们感兴趣的两个字段(包名和节),为了让输出更容易阅读和排序,先打印节,再打印包名。
sort
: 由于部分现在是第一个字段,一个简单的sort
就足以按部分对包进行排序。
最终输出如下所示:
admin accountsservice
admin aptdaemon-data
editors libreoffice-impress
fonts fonts-telu
games enemylines3
games enemylines7
gnome cinnamon
libdevel libxmu-dev
libs libapt-pkg4.12
oldlibs hpijs
python python-gi-cairo
Run Code Online (Sandbox Code Playgroud)