Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find RPM From File Name

Status
Not open for further replies.

gwinn7

Programmer
Feb 10, 2001
1,004
US
Does anyone know the rpm syntax for locating a package when all you have is a file name? The package that I am searching for is not installed, but I am looking for a particular file.

Thanks,
Gary
gwinn7
A+,N+,I+
 
You want to figure out which package contains a certain file, a package that you don't have installed? If so, go to and type in the filename. It should give you a list of packages containing the file.
If you have the package installed and what to find out which package it belongs to, execute
[tt]rpm -q --whatprovides <filename>[/tt]

//Daniel
 
You mean to tell me that there is no RPM option to search for which not-installed RPM has a particular file? I have to resort to a web site for this?

I found what seems to be what I am looking for, but I couldn't get it to work.

rpm -qf 'rpm -qla | grep -I bash' | more

When I ran the above command, it gave me an error indicating that it could process the command. What puzzles me about this is that its straight out of &quot;Red Hat Linux6 for Small Business&quot; book.

Does anyone know what I may be doing wrong? Could it be a problem because I am using Red Hat 8? Any alternative command options?

Gary
gwinn7
A+,N+,I+
 
Unless you have installed the RPM database, how can the RPM system know which package contains a certain file?
Most likely that command doesn't work because the version of RPM has changed from 3.x in RedHat 7.x to 4.1 in RedHat 8.0.

//Daniel
 
Gary are you trying to say that if you have a bunch of rpm files in a directory, how do you check to see which one contains a file? If you don't already have the rpm file, than I'd go with Daniel's method.

-Venkman
 
Also note that the command you have does the same thing as the command provided in my first post, it just searches the installed packages.

//Daniel
 
Daniel,

Yes, unfortunately, I realized that the command I previously suggested will not do what I am asking.

RE: Daniel
--- &quot;Unless you have installed the RPM database, how can the RPM system know which package contains a certain file?&quot;

That's exactly my question and issue. If I can perform the following...

&quot;rpm -qpl *&quot;

The above command should list all files contained in all local rpm's (files only, not installed) and their respective path. I can go even further and limit the output to the file I am looking for...

&quot;rpm -qpl * | grep myfile&quot;

I know this is probably obvious to you all, but this is where my frustration seems to begin. All the above statement does is tell me if at least one of the rpm's in that folder contains the file I am looking for, not which RPM.

I have been studying diligently for the Linux+ exam and I couldn't believe that there wasn't anything in my study materials that revealed a solution. Any further insight?

Anyhow, I really appreciate everyones response and examination of this issue. Thanks.

Gary
gwinn7
A+, N+, I+
 

for i in `rpm -qa`
do
[ grep -q &quot;filename&quot; `rpm -qlp $i` ] && print $i
done

I haven't tested this and I'm not the best scripter around...

Cheers

Henrik Morsing
Certified AIX 4.3 Systems Administration
& p690 Technical Support
 
Thanks! I will give that a try and let you know.

Gary
gwinn7
A+,N+,I+
 
You would probably want to change the [tt]`rpm -qa`[/tt] to list the files in your RPM containing directory, or it will not work.

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top