Friday, April 18, 2008

Finding a File's Owner

I generally gravitate towards Debian derived Linux distributions; although, I spend quite a lot of time on the Red Hat side of the tracks as well. My primary reason for liking Debian and Ubuntu is the package management. I plan on doing a whole series on apt and dpkg tricks in the future, but for the moment, here's a really easy way to find out what package a file belongs to.

travis@travis-desktop:/home/travis% dpkg -S /bin/bash
bash: /bin/bash

Only install from tarballs as a last resort, and you should be able to track down over 90% of the files on your system.


Anonymous said...

same function for pacman (Archlinux): pacman -Qo /path/to/file

Anonymous said...

Awesome, I never looked at the dpkg manpage closely enough to know this! Look s like this is the best way to find what *installed* package a file belongs too.

In the past I've historically used apt-file. I guess apt-file here would be able to tell you what packages provide a file.

$ apt-file search filename

Travis Whitton said...

Didn't know about apt-file. Very cool. I haven't had any experience with Arch Linux, but I'll check it out.

Anonymous said...

While I wouldn't be a fan of redhat/suse type distro's (debian/ubuntu would be my preference)
it is possible to do the same thing with rpm:

rpm -q --whatprovides /bin/bash

You'd probably be rather surprised what your package manager can do for you.

- bobb

Steve Laniel said...

I don't know how dlocate differs from dpkg -S, but I've always used the former to find which package owns files that are currently installed on the system.

Apt-file is useful if the package isn't actually installed yet. If, for instance, some badly-behaved app (likely a non-Debian one) says that it tried and failed to find /path/to/foo, you do

sudo apt-file update
sudo apt-file search /path/to/foo

Travis Whitton said...

Thanks Steve. Good to know!