Finding Which RPM Package Contains a File

October 15th, 2008 by Dashamir Hoxha in

Your rating: None Average: 3.5 (13 votes)

To search a list of RPM files for a particular file, execute the following command:

$ ls RPMS-TO-SEARCH | \
    xargs rpm --query --filesbypkg --package | \
      grep FILE-TO-SEARCH-FOR

Replace RPMS-TO-SEARCH with the names of the RPM files to search, and replace FILE-TO-SEARCH-FOR with the name of the file to search for. The --filesbypkg option tells the rpm command to output the name of the package as well as the name of the file.

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous's picture

Correction for "Another way"

On October 16th, 2008 Anonymous (not verified) says:

D**n... Missed the stated intent of searching uninstalled packages.

The "--whatprovides" switch naturally only searches packages already installed on the system, not the package files.

Sorry for that.

Anonymous's picture

Another way to find the file.

On October 16th, 2008 Anonymous (not verified) says:

Or You could just use RPM's database.

rpm -q --whatprovides FILES_TO_SEARCH_FOR

Rui Lapa's picture

Other Usefull rpm commands

On October 15th, 2008 Rui Lapa (not verified) says:

Same as:
rpm -qlp RPMS-TO-SEARCH | \
grep FILE-TO-SEARCH-FOR

q - query
l - list files
p - packages

Good ones are:
--------------

1. Find the rpm which FILE (path/filename) belongs to
rpm -qf FILE

2. Verify rpm files (changes, MD5, permissions, owner, ...)
rpm -qV RPM_PACKAGE_NAME

3. List packages ordered by SIZE
rpm -qa --qf "%{SIZE} %{NAME}\n" | sort -n

4. Repackage OLD files (make rollback rpm) when upgrading an rpm
rpm --repackage -Uvh NEW_RPM_PACKAGE

Patricio Diaz's picture

rpm -qlp RPMS-TO-SEARCH |

On March 6th, 2009 Patricio Diaz (not verified) says:

rpm -qlp RPMS-TO-SEARCH | grep FILE-TO-SEARCH-FOR will tell you the file name, the directory it will be installed on, and that there is a package containing it, but won't tell you which package is.

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.


Read this issue