How To Find What Package Provided a File?

By | 2009/03/04

Earlier today I found myself in a situation where one Ubuntu machine was missing an executable available on the second. After trying to guess the package name a few times without success I pulled this little number out of my bag of tricks:

[email protected]:~$ dpkg -S $(which host)
bind9-host: /usr/bin/host

As you can see, this returned the package name that provided the executable, host.  Using the -S option with dpkg directly is a really simple way to find out what package provided the file or executable you’re looking for.

This requires, of course, that the file exists on the machine you’re running the command on.  I should also note that the command-not-found package provides this functionality in recent versions of Ubuntu.  If you’re on an Ubuntu variant, or a Debian release that may not provide this service, this is a good tool to be aware of.. just in case.

8 thoughts on “How To Find What Package Provided a File?

  1. Jonathan

    Is there any benefit that way instead of doing
    dpkg -S `which host`

    Or is that just the way you happen to prefer doing it?

    Reply
    1. Christer Edwards Post author

      @Jonathan – I used the $() approach because I despise the use of ` (backticks) in programming. It is all too easy to confuse it for single-quotes and cause problems. $() works in the same way as backticks, but is more readable.

      Reply
  2. tensai

    Check out dlocate. If you’re familiar with locate, it’s the same concept. Instead of parsing all the package files for every search, which dpkg -S does, dlocate builds an index via a crontab and can search lightening quick.

    Reply
  3. etxekalte

    I think that you can achieve the same result for every file with “apt-file search file”

    Reply
  4. Greg

    I prefer to set up apt-file, do an apt-file update, and later an apt-file search.

    Only because dpkg -S does only search in installed packages.

    Reply

Leave a Reply