Thursday, September 25, 2008

Whatprovides

If you're using a RedHat derivative that utilizes yum as it's package manager, you can use the `whatprovides' command to see what package provides a specific file.

Example:

yum whatprovides /usr/bin/vim

... grab a coffee ...

vim-enhanced.x86_64 1:6.3.046-0.40E.7.cent base
Matched from:
/usr/bin/vim

Debian derivatives provide a similar functionality via the apt-file package.

# sudo apt-get install apt-file
# sudo apt-file update
$ apt-file search /usr/bin/diff
diff: /usr/bin/diff

4 comments:

Steve Laniel said...

apt-file will find you files, whether they're installed on your machine or not. dlocate only searches installed packages, and is consequently much much faster.

(11:02) slaniel@dops-slani2:~$ which vim
/usr/bin/vim
(11:04) slaniel@dops-slani2:~$ dlocate `!!`
dlocate `which vim`
vim-tiny: /usr/bin/vim.tiny
vim-gnome: /usr/bin/vim.gnome
vim: /usr/bin/vim.basic
vim-runtime: /usr/bin/vimtutor

egypt said...

The equivalent utility in gentoo is "equery"

$ equery belongs equery
[ Searching for file(s) equery in *... ]
app-portage/gentoolkit-0.2.3-r1 (/usr/share/doc/gentoolkit-0.2.3/equery)
app-portage/gentoolkit-0.2.3-r1 (/usr/bin/equery)
$ equery belongs /usr/bin/vim
[ Searching for file(s) /usr/bin/vim in *... ]
app-editors/vim-7.2 (/usr/bin/vim)

Unknown said...

Its way quicker to use rpm -q --whatprovides that yum whatprovides

$ time rpm -q --whatprovides /usr/bin/vim
vim-enhanced-7.0.109-3.el5.3

real 0m0.085s
user 0m0.012s
sys 0m0.009s

$ time yum whatprovides /usr/bin/vim
Loading "installonlyn" plugin
Setting up repositories
Reading repository metadata in from local files
Excluding Packages in global exclude list
Finished

vim-enhanced.i386 2:7.0.109-3.el5.3 centos5base
Matched from:
/usr/bin/vim

vim-enhanced.i386 2:7.0.109-3.el5.3 installed
Matched from:
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor

real 0m7.382s
user 0m4.366s
sys 0m0.373s

I guess the advantage of using yum is that it can tell you whatprovides for uninstalled packages.

Anonymous said...

Just in case anyone on a Debian-based system missed it:

$ dpkg -S /usr/bin/vim.gnome