# Which package/port provides file xy



## hashime (Oct 20, 2014)

Hello

I am trying to figure out how to use pkg to search not installed packages which contain a specific file. For example I know a binary is called foobar or /usr/local/bin/foobar and I don't know which package (or port) contains that binary, how can *I* find it out with pkg.

For those who are literate in *Linux, *I* am searching an equivalent to `yum provides foobar` or `apt-file search foobar`. Is there something like http://packages.debian.org for FreeBSD?

Any help is appreciated.


----------



## kpa (Oct 20, 2014)

Not possible yet, the remote repository index does not include the list of files contained in the packages.


----------



## scottro (Oct 20, 2014)

The old pkg_info with the -W flag used to do that, but I don't think the function is yet in the new pkg(8). Ok, the man tags don't work for pkg_info, because these link to man pages for FreeBSD-10.  But if you follow the link I made below, and then run a query on FreeBSD-9.0, you can find the man page for it. 

pkg_info()


----------



## ShelLuser (Oct 20, 2014)

Not fully sure but I doubt that this feature is available. The command you're looking for is pkg-search(8), however that manual page states that "_packages can be matched by name, by name and version, by origin or by text in the package comments or package descriptions_".


----------



## ShelLuser (Oct 20, 2014)

scottro said:


> The old pkg_info() with the -W flag used to do that, but I don't think the function is yet in the new pkg(1).


It is, the command you're looking for is pkg-which(8). However, this will only search the local package database (so; only looks for installed packages).


----------



## kpa (Oct 20, 2014)

scottro said:


> The old pkg_info() with the -W flag used to do that, but I don't think the function is yet in the new pkg(1).  He, I can't preview, so hopefully my tags came out right.  Am I missing an option here?  And the man tag isn't linking properly.  Grr.



Nope, that didn't do what the OP is asking for. The old package tools didn't have any sort of repository index that you could use for searching and there for no way to query for the files contained in the remote packages. Instead the -W flag for the old pkg_info did exactly what pkg-which(8) does now.


----------



## hashime (Oct 21, 2014)

Okay, thanks for the quick replies.


----------



## scottro (Oct 21, 2014)

Ah, thank you.  I'd misunderstood an earlier post (in another thread. )


----------



## foo_daemon (Oct 24, 2014)

Here's a one liner that may help you:

If you are looking for what provides a file, for example /usr/local/bin/STUFF , then you can try:
`$ find /usr/ports -iname "pkg-plist*" -maxdepth 3 -exec grep -iH "bin/STUFF" {} \;`

(make sure you do not include /usr/local path in the grep string as this will never match: all pkg-plist files are listed excluding $LOCALBASE which is /usr/local 99% of the time)

There are a few caveats to this approach though:

Might take a while -- actually, scratch that, after I added -maxdepth 3 to the command execution time went from over 6 min to 15 seconds 
Depends on a static pkg-plist, which not all ports use, but I believe the majority do (it is preferred).
plist files can have macros in them, trivial example is if the filename is something like /usr/local/share/PORTNAME/data.txt, these should appear in pkg-plist as %%DATADIR%%/data.txt , so truncating your grep string to the file basename is most likely to work, however this is also most likely to give you a bunch of false-positive results :\


----------



## rosorio (Oct 22, 2019)

Now we have pkg-provides, a pkg plugin.





						FreeBSD Ports Search
					






					www.freebsd.org


----------

