Posted on

Finding Which Linux Packages Provide Which Files

There have been multiple situations where I find out that I need a particular file to continue with something I am doing. Most of the time this happens when I am compiling a program. I will be missing a library, or header file, or something. So I end up on search engines looking for whatever package I need to ‘apt-get install’. Well it turns out there is a command line tool that will tell you this information, on systems use Apt, that is.

Enter ‘apt-file’.

I use Ubuntu, and it doesn’t come with that platform by default. Or at least not on 10.04 then I’m using. But you should know how to get it. A simple ‘apt-get install apt-file’.

Once you have it installed, you will have to update the cache it uses for searching. I was prompted to do this automatically, but if you are not then you can run ‘apt-file update’ to do so.

With that done, the command ‘apt-file find’ will let you list packages that include the given file. For example, I was looking for the program ‘xpidl’, which I didn’t have. Easy to find:

    $ apt-file find xpidl
    kompozer: /usr/lib/kompozer/xpidl
    sunbird-dev: /usr/lib/sunbird/xpidl
    thunderbird-dev: /usr/lib/thunderbird-3.0.3/xpidl
    xulrunner-1.9.1: /usr/lib/xulrunner-
    xulrunner-1.9.1-dbg: /usr/lib/debug/usr/lib/xulrunner-
    xulrunner-1.9.2: /usr/lib/xulrunner-
    xulrunner-1.9.2-dbg: /usr/lib/debug/usr/lib/xulrunner-

You can provide the argument ‘-x’ to use a Perl regular expression as your search query.

You can also see what files are in a package by using the command ‘list’ instead of ‘find’. Unlike the ‘dpkg -L’ command, ‘apt-file list’ will work even if you don’t have the package installed or cached on your system.

I wish I had found this tool years ago.