Find what package a file belongs to in Ubuntu/Debian?
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?
8 Answers 8
apt-file search /path/to/file
sudo apt-get install apt-file
You will need to update its database before you can use it:
FYI: apt-file seems to depend on Contents-amd64.gz provided by repositories. And not all 3rd party repos provide this file.
It did not work for me. I updated the database but it does not return anything. dpkg -S works as described below.
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.
‘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’.
In contrast to apt-file , this also finds the package to a file if it was installed manually via dpkg -i !
If you get dpkg-query: no path found matching pattern try this: dpkg -S «$(readlink -fn «$(which rename)»)» .
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
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.
You can also use dlocate. From the man page;
$ dlocate [ PATTERN ] List all records where either the package name or the filename matches PATTERN.
@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
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. .
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.
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
Find What Files are in a Package in Ubuntu
Packages and repositories are the bread and butter of Linux operating systems. The first step to installing any software on a Linux-based system is to download its package from its respective repository. A package refers to a compressed archive that contains all the files required for a piece of software to execute properly. Typically, packages are downloaded from their corresponding repositories. Common formats of Linux packages include .deb, .rpm and .tgz. This article will learn about various methods to find out what files are included in Linux packages.
Method 1 – Checking files online
Let’s start with the simplest and most user-friendly method to find what files are included in a Linux package. The first step is to visit this link and to use the website, as we demonstrate in the following steps. This method does not require any command-line expertise or installing any external utilities. You can find out the list of files of a package by following these steps:
- Open the http://packages.ubuntu.com/ website in a web browser of your choice.
- Scroll down to ‘Search package directories’.
- Type your package name in the keyword field.
- Check the ‘Show exact matches’ box.
- Select your distribution.
- Press the ‘Search button.
- Specify your architecture and the desired package on the next page.
- Click on ‘list of files’ next to your architecture to get the list of the files in the specific package.
And with that done, you can check out any package and look at what’s inside it. Along with this cool feature, the website also allows users to search for specific files. Then, of course, you can learn more about them through their documentation.
Method 2 – Using dpkg
Dpkg is a tool for building and managing packages in Linux. We can also use it to list the files contained in a package in Ubuntu. Moreover, dpkg can be used for searching a particular file and see which packages use it. Interestingly, dpkg is the main command that plays the role of installing and removing programs on your Linux system. The more commonly known and used apt-get and other similar commands just call dpkg to get the same results. So basically, while using dpkg, you are operating at the very low-level base of the operations. Now, with the essential details out of the way, let us go back to our main concern – using dpkg to determine what files are in a package.
The first step is to open a terminal in Ubuntu. You can either access it through the applications menu or press the shortcut Ctrl + Alt + T.
To list the files of an installed package, we can execute the following command (the ‘$dpkg’ is the name of the package for which the list of files is required)
You can find out which a .deb package will install files through the following simple dpkg command.
However, our main course of action in this tutorial is to show you how you can check the files in a package that is not even installed yet. Worry not, as the small command is given below will do just that.
This command shows the same output as the previous attached image. However, this one would work for packages that are not already installed as well.
As we mentioned earlier, dpkg also allows you to search for a particular file and find which packages contain that file. This functionality can be utilized by appending -S (search flag) with dpkg:
cairo.h is the filename we are looking for. If you know the address of the particular file that you are looking for, you can include it in the command to narrow down the results.
One of the major advantages of using dpkg is that it can be used with packages that are not installed from any repositories.
Method 3 – Using apt-file
apt-file is a Linux package that can list the files contained in a package or search through the package for a particular filename. apt-file can be used to find files of a package that is not installed as well.
First, open a terminal through the application menu or by pressing the shortcut Ctrl + Alt + T.
Before we proceed any further, we first have to install the apt-file package itself. You can do that by running the command given below.
apt-file searches a database to look for packages and their files. It is good practice to update the database before moving on with the search.
Now that everything is up and running, we initiate the search for our required packages. This can be done through the following command.
If you want to search for a particular filename (cairo.h in our case), you can use the command below.
As was the case with dpkg, if you know the address of the file you are searching for, you can specify that too narrow down the search results.
That about covers all there is to using apt-file to find files in a package. However, if you wish to use apt-file to benefit further, the following help commands are for you.
Conclusion
In this article, we have gone through various methods to get a list of the files in a package. Whether you prefer searching with GUI-based online resources or comfortable with the command-line interface, now you know how to get a list of files of any available package.
About the author
Zeeman Memon
Hi there! I’m a Software Engineer who loves to write about tech. You can reach out to me on LinkedIn.
How do I find out which package owns a file?
Alternatively, there are several utilites in Debian which perform this task; check this page for a description. I’ll mention two of them, apt-file and dlocate .
apt-file searches its internal cache, thus allowing you to not install all the packages you want to search. Below you will find more detailed guide.
dlocate is a fast alternative to dpkg -L (the command that lists package contents), and as so, it searches only installed packages. Search is performed by dlocate -S file.name .
Also you can search packages online using packages.debian.org server (the Search the contents of packages section).
Installing and using apt-file
It’s a good idea to update first:
sudo apt-get install apt-file
Read data from repositories (this works also without sudo but creates user’s cache then; with sudo the cache is system-wide):
Perform search. In this example we want to know in which package xrandr executable is:
It lists many packages with unxrandr , lxrandr.mo or source_lxrandr.py . Not very useful in our case. More clever search:
( $ denotes end of line). Example output:
bash-completion: /usr/share/bash-completion/completions/xrandr x11-xserver-utils: /usr/bin/xrandr
The first result doesn’t look like executable, the second one does. We can investigate further. Run:
apt-cache show x11-xserver-utils
Bingo! This is the package.