Home > Ubuntu > How To Find What Package Provided a File?

How To Find What Package Provided a File?

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:

cedwards@monkey:~$ 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.

Categories: Ubuntu Tags: ,
  1. March 4th, 2009 at 22:43 | #1

    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?

    • March 6th, 2009 at 18:10 | #2

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

  2. March 4th, 2009 at 23:23 | #3

    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.

  3. March 5th, 2009 at 00:13 | #4

    Please note that `dpkg -S` will not give you results for links managed by the alternatives system.

  4. March 5th, 2009 at 01:26 | #5

    http://packages.ubuntu.com/ allows you to search the contents of all packages in the archive.

    PS – something seems to be wrong with your OpenID login

  5. etxekalte
    March 5th, 2009 at 01:45 | #6

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

  6. Greg
    March 5th, 2009 at 03:24 | #7

    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.

  7. March 22nd, 2009 at 16:05 | #8

    dpkg only works if you have the package already installed.

    apt-file can do others as well:
    http://kevin.vanzonneveld.net/techblog/article/search_for_a_package_with_aptfile/