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.
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?
@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.
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.
Please note that `dpkg -S` will not give you results for links managed by the alternatives system.
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
I think that you can achieve the same result for every file with “apt-file search file”
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.
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/