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?


7 Answers 7

apt-file search filename


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
  • 9
    FYI: apt-file seems to depend on Contents-amd64.gz provided by repositories. And not all 3rd party repos provide this file.
    – Jokester
    Commented Mar 25, 2015 at 6:27
  • 4
    It did not work for me. I updated the database but it does not return anything. dpkg -S works as described below.
    – Northys
    Commented Dec 28, 2016 at 12:36
  • 1
    In most cases you will not need to install a non-standard package (apt-file) and get away with using the pre-installed one (dpkg). See top voted answer. Commented Oct 17, 2019 at 12:50

(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'.

  • 44
    That is only if the files already installed
    – user1931
    Commented Jul 22, 2009 at 19:16
  • 30
    In contrast to apt-file, this also finds the package to a file if it was installed manually via dpkg -i!
    – tanius
    Commented Feb 28, 2015 at 5:09
  • 5
    If you get dpkg-query: no path found matching pattern try this: dpkg -S "$(readlink -fn "$(which rename)")".
    – Pablo A
    Commented Jul 7, 2017 at 21:02
  • 2
    Weird, this didn't work for me: dpkg-query: no path found matching pattern /usr/bin/java, though there is a file at /usr/bin/java
    – nnyby
    Commented May 23, 2018 at 17:28
  • @nnyby See comment of Pablo A
    – vog
    Commented Oct 2, 2019 at 10:59

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:


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.

  • 1
    It doesn't work with custom repos though.
    – Ctrl-C
    Commented Jun 29, 2018 at 11:40
  • 1
    Poor choice in regards to automation. Commented Aug 1, 2018 at 16:56

You can also use dlocate. From the man page;

$ dlocate [ PATTERN ]
List all records where either the package name or the filename matches PATTERN.
  • 1
    dlocate is also my favorite method, very reliable.
    – Avio
    Commented Sep 16, 2013 at 20:14
  • 2
    @Avio dlocate does not find a recently installed package unless you run sudo update-dlocatedb first. The command is automatically run daily in /etc/cron.daily/dlocate
    – jarno
    Commented Jan 18, 2016 at 11:06

I found Wajig...

wajig whichpackage /path/to/file 


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 ? ! )


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.

  • Now if only Raspbian also had one :)
    – XTL
    Commented May 30, 2015 at 10:39

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
  • This does not work for arbitrary files however, like the OP requested.
    – user
    Commented Mar 12, 2015 at 12:26
  • This is a problematic tip if the program does harmful things and IS installed. Adding -h or --help at the end would help a bit. If adding -h at the end would make this safe enough I would recommend, but even so it is not a good way to achieve what the OP asks.
    – DrBeco
    Commented Apr 27, 2016 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .