# search what port/package provides file "x"



## da1 (Jun 21, 2010)

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.


----------



## SirDice (Jun 21, 2010)

```
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.


----------



## da1 (Jun 21, 2010)

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 ?


----------



## SirDice (Jun 21, 2010)

da1 said:
			
		

> how would I figure out which package/port to install in order to get the file ?


Google :e


----------



## da1 (Jun 21, 2010)

yeah ... cheers mate


----------



## phoenix (Jun 21, 2010)

`$ grep filename /usr/ports/*/*/pkg-plist`
May take a long time to run.    And won't work for ports that use auto-generated plists.


----------



## DutchDaemon (Jun 21, 2010)

http://www.secnetix.de/tools/porgle/porgle.py might help


----------



## fronclynne (Jun 21, 2010)

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).


----------



## wblock@ (Jun 21, 2010)

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`


----------



## phoenix (Jun 21, 2010)

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.


----------



## phoenix (Jun 21, 2010)

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).


----------



## jalla (Jun 21, 2010)

If you had your ports tree around for a few days, this is probably the fastest

```
locate filename |grep 'usr/ports'
```


----------



## wblock@ (Jun 21, 2010)

jalla said:
			
		

> If you had your ports tree around for a few days, this is probably the fastest
> 
> ```
> 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.


----------



## da1 (Jun 22, 2010)

@DutchDaemon - the link looked promising at first but the following changed that:

test1:


```
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.


----------



## jalla (Jun 22, 2010)

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.


----------



## jalla (Jun 22, 2010)

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


```
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
```


----------



## duckunix (Mar 24, 2014)

And for completeness sake (I found this thread via google), under pkgng, the way to do it is:

```
pkg which<file>
```
Works like a champ for ports installed or binary package installed ports.


----------



## wblock@ (Mar 24, 2014)

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.


----------



## scottro (Aug 1, 2018)

4 years later, for me, (trying various things from this thread) the find command given worked well, and didn't take that long.


```
cd /usr/ports
find . -name pkg-plist |xargs grep mp4info
```
  (which was the program I was seeking).  Took about 30 seconds.


----------



## SirDice (Aug 1, 2018)

A lot of ports have a dynamically generated pkg-plist, so this file doesn't always exist.


----------



## b6s6d6 (Aug 1, 2018)

Nowadays there's an utility called ports-mgmt/pkg-provides


----------



## drhowarddrfine (Aug 1, 2018)

b6s6d6 Hadn't heard of that one. I installed it but `pkg provides bin/firefox$` and any other combination from the man page always returns 





> pkg: unkown command: provides


----------



## SirDice (Aug 1, 2018)

Did you read the pkg-message? You need to enable plugins in /usr/local/etc/pkg.conf.


----------



## drhowarddrfine (Aug 1, 2018)

Yeah I missed it.


----------



## Chris_H (Aug 1, 2018)

Mm... maybe `make show-depends` ?

--Chris


----------



## drhowarddrfine (Aug 1, 2018)

Don't you mean `make depends`? But that shows what a port depends on. He wants the reverse. Where did a file come from.


----------



## Chris_H (Aug 2, 2018)

`make depends` _makes_ the dependencies. Which is _far_ from _showing_ the dependencies. 
So. No. I meant `show-depends`. But you're right in the respect that it doesn't (necessarily) show where a file came from. But my intention was to show there are other ways more powerful than pkg(7) to learn about ports -- whether already installed, or one you might _want_ to install. `make show-depends` provides a great deal of information about something _not_ installed. That `pkg` just can't give. You could -- if you were crazy enough; `cd /usr/ports` and perform a search via find(1) piping the output to grep(1), then piping that outut to `make show-depends` finally redirecting that output to a file. Thereby giving you all (more than) the information you could ever hope to want. 
But that would be crazy. There are a number of additional commands in this category that would likely be (more) helpful in finding where something came from, or _why_ something (unwanted) got pulled in, and from _where_. It's all pretty well documented in make(1). 

HTH

--Chris


----------



## drhowarddrfine (Aug 2, 2018)

Chris_H  Oh, well, wait. You're right. I confused myself. Probably cause `make show-depends` doesn't work on my system. Why is that?


----------



## ShelLuser (Aug 2, 2018)

drhowarddrfine said:


> Chris_H  Oh, well, wait. You're right. I confused myself. Probably cause `make show-depends` doesn't work on my system. Why is that?


Because show-depends is not a valid target, see also ports(7).

The targets which will work are: all-depends-list, run-depends-list and build-depends-list.


----------



## Chris_H (Aug 2, 2018)

Crap! Got me. 
I'm wearing _far_ too many hats simultaneously. Sigh...

Thanks for the correction, ShelLuser !

--Chris


----------



## drhowarddrfine (Aug 2, 2018)

ShelLuser said:


> Because show-depends is not a valid target


Thus my point.


----------



## scottro (Aug 2, 2018)

I am finding pkg-provides to work well, and again thank b6s6d6 for recommending it.   I seldom need it, (for example, in CentOS, I need it more frequently as I try to compile a 3rd party program) but it does work quite well.


----------



## b6s6d6 (Aug 2, 2018)

scottro said:


> I am finding pkg-provides to work well, and again thank b6s6d6 for recommending it.   I seldom need it, (for example, in CentOS, I need it more frequently as I try to compile a 3rd party program) but it does work quite well.


No problem


----------



## neo (Dec 21, 2018)

pkg info -l /path/file


----------



## ShelLuser (Dec 22, 2018)

neo said:


> pkg info -l /path/file


That will only produce an error, see also pkg-info(8). The -l switch is used to list the contents of one of more packages, ergo you can't use a file as parameter.

info isn't the right command for this anyway, that would be pkg-which(8).


----------



## olli@ (Dec 27, 2018)

DutchDaemon said:


> http://www.secnetix.de/tools/porgle/porgle.py might help


Just for the record, that tool moved to a different web server:
http://inof.de/FreeBSD/porgle/
Among other things, it can be used to search for ports that provide a certain file. Also supports regular expressions.


----------



## miklosq (Apr 22, 2019)

ShelLuser said:


> That will only produce an error, see also pkg-info(8). The -l switch is used to list the contents of one of more packages, ergo you can't use a file as parameter.
> 
> info isn't the right command for this anyway, that would be pkg-which(8).



Correct. For sake of completeness, in case of using the *pkg* package management tool, the command is `pkg which file-or-directory-to-search-for,` like in the below example:


```
# locate firefox | grep bin
/usr/local/bin/firefox
/usr/local/lib/firefox/firefox-bin
# pkg which /usr/local/bin/firefox
/usr/local/bin/firefox was installed by package firefox-66.0.3,1
#
```


----------



## dvl@ (Jul 19, 2019)

FreshPorts can search pkg-plist for file names which match the file you want.


----------



## rtobiasr (Feb 1, 2022)

SirDice said:


> Google :e


I have tried every iteration of what package provides nmtui. All I get is usage examples of nmtui. BTW: it doesn't appear to be networkmgr. "Google it" isn't very nice.


----------



## da1 (Feb 1, 2022)

rtobiasr said:


> I have tried every iteration of what package provides nmtui. All I get is usage examples of nmtui. BTW: it doesn't appear to be networkmgr. "Google it" isn't very nice.


SirDice isn't very nice either


----------



## jmos (Feb 1, 2022)

rtobiasr said:


> I have tried every iteration of what package provides nmtui. All I get is usage examples of nmtui. BTW: it doesn't appear to be networkmgr. "Google it" isn't very nice.


Afaik: `nmtui` is part of the GNOME Network Manager, which is "Linux only"; You can't get it for FreeBSD, and that's why you won't find a package containing it.


----------

