dpkg -s
确实将包名称而不是文件或程序作为参数。(在许多情况下,一个程序将与提供它的包同名。)
例如,在我的 Ubuntu 系统上,dpkg -s gcc
打印:
Package: gcc
Status: install ok installed
Priority: optional
Section: devel
Installed-Size: 64
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: i386
Source: gcc-defaults (1.98ubuntu3)
Version: 4:4.5.2-1ubuntu3
Provides: c-compiler
Depends: cpp (>= 4:4.5.2-1ubuntu3), gcc-4.5 (>= 4.5.2-1~)
Recommends: libc6-dev | libc-dev
Suggests: gcc-multilib, make, manpages-dev, autoconf, automake1.9, libtool, flex, bison, gdb, gcc-doc
Conflicts: gcc-doc (<< 1:2.95.3)
Description: The GNU C compiler
This is the GNU C compiler, a fairly portable optimizing compiler for C.
.
This is a dependency package providing the default GNU C compiler.
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
在 CentOS 系统上,rpm -q gcc
打印:
gcc-4.1.2-50.el5
它不会打印太多信息,但是如果您所做的只是检查是否安装了软件包,那应该没问题。如果您需要更多信息或其他选择,man rpm
; 其他查询可用。
如果rpm -q snmpd
prints package snmpd is not installed
,那可能就是您需要的信息。
两者dpkg -s
并rpm -q
相应地设置退出状态,如果未安装包则报告失败。