单行检查已安装的Linux包服务

e37o9pze  于 2022-09-19  发布在  Linux
关注(0)|答案(1)|浏览(175)

我想在一行中使用rpm命令检查是否安装了特定的Linux包。然而,作为服务存在,它总是给我一个积极的结果,即使没有安装httpd,您能在这里指出问题吗?

rpm -qa httpd && echo "service present" || echo " service not present"
dwbf0jvd

dwbf0jvd1#

使用以下代码替换<PACKAGE_NAME>

更短

rpm -q <PACKAGE_NAME> && echo "service present" || echo "service not present"

加长

rpm -qa <PACKAGE_NAME> | grep <PACKAGE_NAME> && echo "service present" || echo "service not present"

示例:

rpm -qa httpd | grep httpd && echo "service present" || echo "service not present"

# Output

[root@bfa3155b8feb /]# rpm -qa httpd | grep httpd && echo "service present" || echo "service not present"
service not present

相关问题