Finding which package contains a file

There are times when you’re looking for a particular library, or file, which you know is available to Debian but you cannot find the package which contains it. This is the kind of job that the Debian packages site helped with in the past, but given its current unavailability we’ll look at another approach.

Finding the package which has installed a particular file upon your system is accomplished via the dpkg command. This can be used as follows:

steve@skx2:~$ dpkg –search /etc/bash_completion

bash: /etc/bash_completion

Here we’ve used the –search argument to discover which locally installed package placed the file /etc/bash_completion upon the system – and it showed us that the file belongs to the bash package.

But what if you know you need to find a particular file to finish a compilation? And you don’t know which package it is contained in?

The solution to this related problem is to use the apt-file command. This will allow you to search the files which are contained in packages.

Install it with:

apt-get install apt-file

Once installed you’ll need to download the actual data which it uses to search. This can be accomplished with the following command:

apt-file update

Once you’ve downloaded data you can now proceed to searching for packages.

Recently I wanted to compile some software and I didn’t know which package contained the header I neede to use (alisp.h). Using apt-file i it was simple to find out:

skx@itchy:~$ apt-file search alisp.h

libasound2-dev: usr/include/alsa/alisp.h

That showed me that the package libasound2-dev contains the file alisp.h. Once I’d installed the package I was able to compile the code I’d downloaded.

You must be logged in to post a comment.