9

Given the name of a binary (or any other program). How to find out which package provides this binary?

Note: Assuming one uses apt/dpkg for package managing.

Edit

Additional to the correct answer below, I'd like to add some further information: In the question above I was assuming that the corresponding package was installed. If this is not the case, there is a package called apt-file which could do the job anyway.

Searching for the mysqldump tool could be done with

$ apt-file --regexp search .*mysqldump$

Resulting in:

mariadb-client-10.0: /usr/bin/mysqldump
mysql-client-5.5: /usr/bin/mysqldump

This solution was found here but I thought it could be of use to mention it here.

Matthias
  • 993
  • 1
  • 11
  • 22

2 Answers2

13

You want dpkg. Specifically the -S option will find which package owns a file.

An example:

$ dpkg -S /usr/bin/whereis
util-linux: /usr/bin/whereis

The example shows that util-linux is the package which contains /usr/bin/whereis.

Matthias
  • 993
  • 1
  • 11
  • 22
criswell
  • 651
  • 6
  • 5
  • 2
    also [How to find out which (not installed) package a file belongs to?](http://unix.stackexchange.com/questions/6311/how-to-find-out-which-not-installed-package-a-file-belongs-to) – steeldriver Aug 19 '15 at 13:03
3
dpkg --search /usr/bin/mysqldump
dpkg -S /usr/bin/mysqldump

The argument of dpkg --search is a shell wildcard pattern, so you can do things like dpkg -S bin/*dump.

Alternatively, you can search the database manually — it's just text files.

grep mysqldump /var/lib/dpkg/info/*.list

On a system with a lot of packages installed, dpkg -S can be slow because it has to read a lot of small files in /var/lib/dpkg/info. You can install dlocate which indexes files installed via deb packages in the same way that locate indexes all files: the information is a bit stale (by default, the database is updated nightly) but the query operation is faster.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175