This site is now 100% read-only, and retired.

Finding which package contains a file

Posted by Steve on Wed 18 Jan 2006 at 16:53

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.

 

 


Re: Finding which package contains a file
Posted by daveseff (208.251.xx.xx) on Wed 18 Jan 2006 at 19:13
Thank you. I've been looking for how to do this for a while.

[ Parent ]

Re: Finding which package contains a file
Posted by outreal (82.239.xx.xx) on Wed 18 Jan 2006 at 21:48
Great tip, I still remember with great joy the day I discovered apt-file...
Another useful command is dpkg -L <package>, which shows all the files installed by a given package.

[ Parent ]

Re: Finding which package contains a file
Posted by Steve (82.41.xx.xx) on Wed 18 Jan 2006 at 22:06
[ View Weblogs ]

For some reason I always forget about "dpkg -L" and end up reading /var/lib/dpkg/info/packageName.list!

Steve

[ Parent ]

Re: Finding which package contains a file
Posted by outreal (82.239.xx.xx) on Wed 18 Jan 2006 at 22:34
Well, for me it's quite the contrary, I must admit that the only dpkg option I can remember is dpkg -L ... :-)

[ Parent ]

And auto-apt
Posted by ineiti (81.221.xx.xx) on Thu 19 Jan 2006 at 00:07

Hi
another nice command is auto-apt. For searching files, it's the same thing:

auto-apt update
auto-apt search test.h
but it can do even more. If you run it with
auto-apt run ./configure
in your standard not-yet-released-in-debian package, then auto-apt will prompt you on every file it knows could be on your computer, if only you'd have that package installed...

Unfortunatly, it doesn't take

deb file://
sources from sources.list.

Ineiti

[ Parent ]

Re: Finding which package contains a file
Posted by Anonymous (80.219.xx.xx) on Thu 19 Jan 2006 at 02:59
Another functionality provied by packages.debian.org are the Changelogs. Since the site is down, requesting a Changelog in synaptic shows the same "error message" as the site. Is there any other way to get to the changelogs?

[ Parent ]

Re: Finding which package contains a file
Posted by Steve (82.41.xx.xx) on Thu 19 Jan 2006 at 07:14
[ View Weblogs ]

Using apt-listchanges will show you the changelog of packages you're upgrading.

Failing that you can see the changelogs of packages you have installed in /usr/share/packageName/.

Steve

[ Parent ]

Re: Finding which package contains a file
Posted by dkg (128.59.xx.xx) on Tue 24 Jan 2006 at 20:56
[ View Weblogs ]
actually, the changelogs are stored under /usr/share/doc/packageName/.

apt-listchanges is a great. i use it to keep myself up-to-date about what's happening in debian, particularly on a relatively well-used testing/unstable system.

[ Parent ]

Re: Finding which package contains a file
Posted by Steve (82.41.xx.xx) on Wed 25 Jan 2006 at 09:44
[ View Weblogs ]

Of course you are correct. I must have typed that too quickly to make such a silly mistake!

Steve

[ Parent ]

Re: Finding which package contains a file
Posted by MrJamesK (24.209.xx.xx) on Thu 19 Jan 2006 at 04:54
The best utility for determining which file belongs to which packge, in my opinion, is wajig.
james@moleman:~$ wajig
JIG> help   
Common JIG commands:

 update         Update the list of down-loadable packages

 new            List packages that became available since last update
 newupgrades    List packages newly available for upgrading

 install        Install (or upgrade) one or more packages or .deb files
 remove         Remove one or more packages (see also purge)

 toupgrade      List packages with newer versions available for upgrading
 upgrade        Upgrade all of the installed packages or just those listed

 listfiles      List the files that are supplied by the named package
 listnames      List all known packages or those containing supplied string
 whatis         For each package named obtain a one line description
 whichpkg       Find the package that supplies the given command or file

Run LIST-COMMANDS for a complete list of commands.


JIG> whichpkg alsamixer
File Path                                                   Package          
===========================================================-===== ============
/usr/bin/alsamixer                                          alsa-utils       
/usr/share/doc/alsa-utils/README.alsamixer                  alsa-utils       
/usr/share/man/man1/alsamixer.1.gz                          alsa-utils       
JIG> 

It is extremely powerful and you don't have to use the pseduo-shell it creates.
All the commands/options can be called from the command at the prompt.

[ Parent ]

Re: Finding which package contains a file
Posted by Anonymous (71.240.xx.xx) on Thu 19 Jan 2006 at 13:58
I like dlocate:

dlocate -S /etc/bash_completion

or

dlocate -L bash

[ Parent ]

Re: Finding which package contains a file
Posted by Anonymous (213.207.xx.xx) on Fri 20 Jan 2006 at 15:13
I use apt-file update but :
Error: cp: cannot stat `/cdrom/dists/unstable/Contents-i386.gz': No such file or directory
I use Debian Sarge DVD and in dists/unstable or dists/[sarge stble unstable] no any Content* file !!

[ Parent ]

Re: Finding which package contains a file
Posted by Anonymous (194.149.xx.xx) on Mon 20 Feb 2006 at 19:24
nice but what about updates?

--20:20:18-- http://security.debian.org//dists/stable/updates/Contents-i386.gz
=> `/var/cache/apt/security.debian.org_dists_stable_updates_Contents -i386.gz'
Resolving security.debian.org... 82.94.249.158, 128.101.80.133, 194.109.137.218
Connecting to security.debian.org[82.94.249.158]:80... connected.
HTTP request sent, awaiting response... 404 Not Found
20:20:18 ERROR 404: Not Found.

[ Parent ]

Re: Finding which package contains a file
Posted by sebas (82.171.xx.xx) on Fri 11 Aug 2006 at 14:44
[ View Weblogs ]
Thanks for the useful tips! I have one question however. I noticed that some configuration files aren't shown in the lists returned by these tools. For instance 'dpkg -S sudo' does not return /etc/sudoers. I read that this is because this file is created during the installation process. Anyone got any ideas on how to retrieve these configuration files?

[ Parent ]

Re: Finding which package contains a file
Posted by Anonymous (217.162.xx.xx) on Thu 21 Jun 2007 at 12:06
Well,

You could see those (some) configuration files with:
#debsums -e <packagename>
And the one you changed (maybe more interessting)
 #debsums -ce <packagename>


In your example
    #debsums -e sudo
does not list:
    /etc/sudoers

And also Files like:
    /etc/apache2/httpd.conf or
    /etc/apache2/ports.conf
are not listed (unfortunately like most configuration files).

Like you wrote, those files are dynamically generated during installation.
I do not know of any system (except file integrity/alteration checker [like samhain, tripwire or maybe FAM.])
which could track this.


If anyone knows another solution, I would love to hear it.


btw. where did you read this?
"I read that this is because this file is created during the installation process"

Cheeers

[ Parent ]

Re: Finding which package contains a file
Posted by Anonymous (85.194.xx.xx) on Sat 25 May 2013 at 18:10
Excellent tool, thank you very much!

[ Parent ]