linux package services installed checked by single line

Viewed 32

I want to check whether a specific Linux package has been installed or not using th rpm command in a single line. However , it's always giving me a positive result as service present, even if httpd is not installed, can you please point out issue here?

rpm -qa httpd && echo "service present" || echo " service not present"
1 Answers

Use the following by substituting the <PACKAGE_NAME>

Shorter

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

Longer

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

Example:

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

Related