Question: I generally use
rpm -qa | grep command to find which package the command belongs to. However, the grepped out would list multiple package names and sometimes even the wrong package names matching the search pattern. I was thinking if there is a better way to do this in CentOS? – Pavithra
Solution: Find which package the command belongs to
All you need is a simple command as shown below:
# rpm -qf $(which <command>)
# rpm -qf $(which update-crypto-policies) crypto-policies-scripts-20211116-1.gitae470d6.el8.noarch
# rpm -qf `which update-crypto-policies`
Alternatively, you can try the below command as well.
# which <command> | xargs rpm -qf
# which update-crypto-policies | xargs rpm -qf crypto-policies-scripts-20211116-1.gitae470d6.el8.noarch
You may also use
yum commands to find the same.
# dnf provides `which update-crypto-policies` crypto-policies-scripts-20210209-1.gitbfb6bed.el8_3.noarch : Tool to switch between crypto policies Repo : baseos Matched from: Filename : /usr/bin/update-crypto-policies crypto-policies-scripts-20210617-1.gitc776d3e.el8.noarch : Tool to switch between crypto policies Repo : baseos Matched from: Filename : /usr/bin/update-crypto-policies crypto-policies-scripts-20211116-1.gitae470d6.el8.noarch : Tool to switch between crypto policies Repo : @System Matched from: Filename : /usr/bin/update-crypto-policies crypto-policies-scripts-20211116-1.gitae470d6.el8.noarch : Tool to switch between crypto policies Repo : baseos Matched from: Filename : /usr/bin/update-crypto-policies
# yum provides `which update-crypto-policies`
Not a recommended method:
But if you grep the output of
rpm -qa, then it would result in multiple package names.
# rpm -qa |grep crypto crypto-policies-20211116-1.gitae470d6.el8.noarch python3-cryptography-3.2.1-5.el8.x86_64 crypto-policies-scripts-20211116-1.gitae470d6.el8.noarch
As you had rightly pointed out, the search pattern ‘crypto’ matches with multiple package names and you need to execute another command to find which package it belongs to.
For example, you need to list the files included with the package and grep its output as shown below:
# rpm -ql crypto-policies-scripts | grep update-crypto-policies /usr/bin/update-crypto-policies /usr/share/crypto-policies/python/__pycache__/update-crypto-policies.cpython-36.opt-1.pyc /usr/share/crypto-policies/python/__pycache__/update-crypto-policies.cpython-36.pyc /usr/share/crypto-policies/python/update-crypto-policies.py /usr/share/man/man8/update-crypto-policies.8.gz
But this check needs to be done with every package listed by the
rpm -qa command. So this is not the ideal way to find the package.
dpkg -S $(which update-crypto-policies)
Note: The command used in the examples is ‘
update-crypto-policies‘ which is used to set/change system-wide crypto policies. You need to replace it with the command of your choice.