Some times it’s require to find which package/application provide a command or a file or even a directory in Redhat based machines. yum/rpm commands will come to your rescue to find that.

Scenario: Recently we tried to install a command on a different machine which is already installed in one of our machines but not sure which package provides that command. If we find which package provide that package, that will save us not to install unnecessary packages in the process of installing this command.

Redhat provids options with yum and rpm commands to check for the package name if we give file name to these commands.

Finding package name which install a particular file in the machine by using yum command.

Syntax:

yum provides /path/to/your/file

Example: For example I want to find which package provides script command in Linux?

yum provides /usr/bin/script

Output:

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: centos.aol.in
* extras: centos.aol.in
* updates: centos.aol.in
util-linux-ng-2.17.2-12.9.el6.i686 : A collection of basic system utilities
Repo : base
Matched from:
Filename : /usr/bin/script

 util-linux-ng-2.17.2-12.4.el6.i686 : A collection of basic system utilities

Repo : installed
Matched from:
Other : Provides-match: /usr/bin/script

Finding package name which install a particular file in the machine by using rpm command.

Syntax:

rpm -qf /path/to/your/file

Example: For example I want to find which package provides script command in Linux?

rpm -qf /usr/bin/script

Output:

util-linux-ng-2.17.2-12.4.el6.i686

This will come handy when dealing with installing new packages.

Example: I want to check what package is responsible for installing /etc/init.d folder in Linux

rpm -qf /etc/init.d

Output:

chkconfig-1.3.47-1.el6.i686

Make a note that -q for query and -f for mention file. And everything in Linux is treated as file which include directory file as well. Know more about different file types available in Linux.

Stay tuned to more updates.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.