我需要显示总数,但我只找到了列出已安装软件包的命令:
ls -l /var/log/packages/
答案1
使用wc -l
将打印总行数。使用管道将您的ls
内容放入其中
ls /var/log/packages | wc -l
这将为您提供 /var/log/packages 中安装的软件包总数。我在命令中省略的原因-l
是因为在大多数情况下,它将在目录列表的顶部打印总块计数,这将有助于您的结束行计数。
答案2
根据 中的以下评论,从而不是installpkg
获取有关已安装软件包的信息可能更适合未来:/var/lib/pkgtools/packages/
/var/log/packages
# Mon Jun 4 21:17:58 UTC 2018
# Migrate the package database and directories from /var/log to
# /var/lib/pkgtools. /var/log was never a good place for this data, as it is
# considered by many to be a directory that could be wiped to free up some
# space.
截至撰写本文时,它看起来像是/var/log/packages
符号链接,/var/lib/pkgtools/packages/
因此目前仍然有效,但尚不清楚此链接是否被设计为临时或永久,这意味着完全绕过该链接可能是最安全的。
lrwxrwxrwx 1 root root 24 Jun 14 2022 /var/log/packages -> ../lib/pkgtools/packages/