search what port/package provides file "x"

hello fellas,


I would like to know how I can search for a package if I only know the file name. simply put, how to check which port provides file "x" or "y".

similar to "yum whatpovides".

I remember I was doing it long ago but i forgot how.
 
Code:
root@molly:/usr/ports#pkg_info -W /usr/local/bin/sudo
/usr/local/bin/sudo was installed by package sudo-1.7.2.5

See pkg_info(1). Only works for installed packages though.
 
mmm, thx for that but I know it already.

I am looking for something different thow. imagine I need to get file "libsdc++" and I dnt know which port contains it. how would I figure out which package/port to install in order to get the file ?
 
$ grep filename /usr/ports/*/*/pkg-plist
May take a long time to run. :) And won't work for ports that use auto-generated plists.
 
phoenix said:
$ grep filename /usr/ports/*/*/pkg-plist
May take a long time to run. :) And won't work for ports that use auto-generated plists.

/sbin/grep: Argument list too long.

I don't feel like doing it, but find(1) can probably handle it (slowly).
 
phoenix said:
$ grep filename /usr/ports/*/*/pkg-plist
May take a long time to run. :) And won't work for ports that use auto-generated plists.

That gives "/usr/bin/grep: Argument list too long." Have to resort to find:
# find /usr/ports -name pkg-plist -exec grep filename {} \+

Using a port search is sometimes worth a try:
# cd /usr/ports && make search key=filename
 
Hrm, yeah, guess that would be along argument list.

Wonder how the speed would compare to (find vs xargs) (completely untested):
Nevermind, that also gives argument list too long.
 
wblock said:
That gives "/usr/bin/grep: Argument list too long." Have to resort to find:
# find /usr/ports -name pkg-plist -exec grep filename {} \+

To speed things up, you can add -depth 3 the find command. That way, it won't search through any sub-directories of the port (old work/ dirs, files/ dir, etc).
 
If you had your ports tree around for a few days, this is probably the fastest
Code:
locate filename |grep 'usr/ports'
 
jalla said:
If you had your ports tree around for a few days, this is probably the fastest
Code:
locate filename |grep 'usr/ports'

But that won't look in the pkg-plist files. It would work to find the port that uses a certain distfile or patch file.
 
@DutchDaemon - the link looked promising at first but the following changed that:

test1:

Code:
pkg_info -L libXi-1.2.1,1
[...]
/usr/local/lib/libXi.so.6
[...]

so let's say I need libXi.so.6, I don't have it installed and I have no clue as to which package it belongs to.

I checked the file in the link you provided me but it does not give me back the "libXi" package. Under a "yum system" I would use "yum whatprovides <filename>" and I am curious if there is something similar under BSD.
 
wblock said:
But that won't look in the pkg-plist files. It would work to find the port that uses a certain distfile or patch file.

You're right, it won't work for everybody. I have a habit of never doing 'make clean' when building ports so my locate db usually contains everything from all ports I ever built.
 
phoenix said:
Hrm, yeah, guess that would be along argument list.

Wonder how the speed would compare to (find vs xargs) (completely untested):
Nevermind, that also gives argument list too long.

Strange, I don't get arg list to long. If it does you can use xargs -L to limit the cmd.

Anyway, it takes about 2,5 minutes

Code:
gnome:/usr/ports# time eval "find . -name pkg-plist | xargs grep whatever"
./databases/mantis/pkg-plist:%%WWWDIR%%/library/ezc/Base/src/exceptions/whatever.php
./games/lucidlife/pkg-plist:%%DATADIR%%/patterns/jslife/odds_&_ends/whatever.glf
./sysutils/gsmartcontrol/pkg-plist:%%PORTDOCS%%%%DOCSDIR%%/LICENSE_whatever.txt
./textproc/stardict2-rptts/pkg-plist:share/WyabdcRealPeopleTTS/w/whatever.wav
./textproc/yodl/pkg-plist:bin/yodl2whatever
./textproc/yodl/pkg-plist:%%NO_MANPAGES%%man/man1/yodl2whatever.1.gz
1.543u 7.433s 2:33.86 5.8%      34+810k 52613+0io 0pf+0w
 
And for completeness sake (I found this thread via google), under pkgng, the way to do it is:
Code:
pkg which<file>
Works like a champ for ports installed or binary package installed ports.
 
There are two different things here. The original thread is about finding out which port to install to get a certain file. pkg which is used in the opposite situation, when a file has been installed and you want to find out which port it came from.
 
4 years later, for me, (trying various things from this thread) the find command given worked well, and didn't take that long.

Code:
cd /usr/ports
find . -name pkg-plist |xargs grep mp4info
(which was the program I was seeking). Took about 30 seconds.
 
A lot of ports have a dynamically generated pkg-plist, so this file doesn't always exist.
 
Did you read the pkg-message? You need to enable plugins in /usr/local/etc/pkg.conf.
 
Back
Top