Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I frequently find myself missing a program, man page, or other file when working on my Ubuntu 8.04 system. Is there any simple way to look up what package contains a given file (whether it is installed already or not)? Maybe some obscure option for apt or dpkg?

share|improve this question

8 Answers 8

up vote 93 down vote accepted
apt-file search filename

or

apt-file search /path/to/file


To install apt-file, use:

sudo apt-get install apt-file

You will need to update its database before you can use it:

sudo apt-file update
share|improve this answer
7  
apt-file package needs to be installed, and isn't by default. –  jtimberman Jul 22 '09 at 19:13
1  
Still relevant on 11.10. –  François Beausoleil Aug 28 '12 at 17:51
2  
Shouldn't the third command be sudo apt-get install apt-file? –  Giorgio Jan 19 '13 at 18:10
    
@Giorgio, done. –  Joel Sjögren Jul 5 '13 at 19:31

(Debian/Ubuntu) Discover what package a file belongs to:

dpkg -S /usr/bin/ls

'dpkg -S' just matches the string you supply it, so just using 'ls' as an argument matches any file from any package that has 'ls' anywhere in the filename. So usually it's a good idea to use an absolute path. You can see in the second example that 12 thousand files that are known to dpkg match the bare string 'ls'.

share|improve this answer
15  
That is only if the files already installed –  John T Jul 22 '09 at 19:16

packages.debian.org is what I always use to accomplish this task. It is superior over apt-file because it can find parts of filenames as well. It's also linked up to the main packages list which will list descriptions, bugs, etc. All in all a good website. Not as useful from the command line, but still quite useful.

For speed, I bookmarked the url:

http://packages.debian.org/search?searchon=contents&keywords=%s&mode=filename&suite=unstable&arch=any

in Firefox, and added "debfind" as a keyword (click "more" in the bookmark manager with it hilighted), so I can just type "debfind " and it will work. You can change 'suite' it from unstable to stable or testing if you like, for other versions of the distribution.

share|improve this answer

You can also use dlocate. From the man page;

$ dlocate [ PATTERN ]
List all records where either the package name or the filename matches PATTERN.
share|improve this answer
    
dlocate is also my favorite method, very reliable. –  Avio Sep 16 '13 at 20:14

Try searching for files using http://www.kodkast.com/applications/find-which-package-file-belongs-to

This is an application to search for files which are contained in different rpms/linux packages, and is very useful when you dont even have the rpm installed on your machine.

share|improve this answer

I found Wajig...

wajig whichpackage /path/to/file 

eg.

wajig whichpackage /etc/apt/sources.list

Wajig is a handy command line or console tool which wraps all the apt-get, dpkg goodness that you never wanted to learn. .

To install wajig use:

apt-get install wajig

That command 'whichpackage' itself depends on apt-file

you will still need to update its database before you can use it: - I don't know yet if wajig update whixh does an apt-get update also updates the file cache, but I expect it may.

sudo wajig update

sudo apt-file update

( and Super Cow, Easter egss ? ! )

share|improve this answer

Simmilar to jamuraa's answer for Debian, you can also go to http://packages.ubuntu.com/ for Ubuntu. You'll have to scroll down a bit to find the "Search the contents of packages" searchbox where you can enter the path of a file.

share|improve this answer

The command-not-found package gives you hints about potential commands and the name of the debian package. It works by typing the command in the bash shell and looking at its output.

For example if the command name is known:

zer@ivy:~ 10:45 $ zsh5
The program 'zsh5' is currently not installed.  To run 'zsh5' please ask
your administrator to install the package 'zsh'
zsh5: command not found

and if the command is not known, some guesses are applied:

zer@ivy:~ 09:46 $ zsh
No command 'zsh' found, did you mean:
 Command 'lsh' from package 'lsh-client' (main)
 Command 'osh' from package 'omake' (main)
 Command 'ysh' from package 'libyaml-shell-perl' (main)
 Command 'ssh' from package 'openssh-client' (main)
 Command 'vsh' from package 'crystalspace' (main)
 Command 'dsh' from package 'dsh' (main)
 Command 'ash' from package 'ash' (main)
 Command 'msh' from package 'nmh' (main)
 Command 'zssh' from package 'zssh' (main)
 Command 'qsh' from package 'gridengine-client' (main)
 Command 'sh' from package 'dash' (main)
 Command 'bsh' from package 'bsh' (main)
zsh: command not found
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.