On Ubuntu, Debian or Linux Mint, there are multiple ways to find out which package a particular file belongs to. This article describes two methods, both of which can be implemented through the command line.
From the same series:
- How to prevent packages from being updated in Ubuntu, Debian or Linux Mint [APT]
- How to search for available packages from the command line in Debian, Ubuntu or Linux Mint [APT]
- How to list all packages in the repository on Ubuntu, Debian or Linux Mint [APT]
1. Use apt-file to find the software package that provides the file (for the repository software package, it is installed or not installed)
apt-file indexes the contents of all available packages in the repository and allows you to search for files in all these packages.
This means that you can use apt-file to search for files in DEB packages that are already installed on your system and packages that are not installed on Debian (and Debian-based Linux distributions such as Ubuntu) computers, but are available for use. Install from repository. This is useful if you want to find which software package contains the files needed to compile certain programs, etc.
If you downloaded the DEB package and installed it without using the repository, apt-file cannot find the package that provides the file. This package needs to be available in the apt-file repository to find it.
apt-file may not be installed on your system. To install it in Debian, Ubuntu, Linux Mint and other Debian-based or Ubuntu-based Linux distributions, use the following command:
sudo apt install apt-file
This tool uses a database to find files belonging to a software package, and it needs to be updated to use it. To update the apt-file database, use:
sudo apt-file update
Now, you can use apt-file to find DEB packages that provide files, whether they are packages you installed from the repository, or packages available in the repository but not installed on Debian / Ubuntu / Linux Mint systems. To do this, run:
apt-file search filename
filename With the name of the file you are looking for.
This command will list all occurrences
filename Found in various packaging. If you know the exact file path and file name, you can get the search results to list only the packages that contain the exact file, as follows:
apt-file search /path/to/filename
For example, just run
apt-file search cairo.h A large list of search results will be listed:
$ apt-file search cairo.h fltk1.3-doc: /usr/share/doc/fltk1.3-doc/HTML/group__group__cairo.html ggobi: /usr/include/ggobi/ggobi-renderer-cairo.h glabels-dev: /usr/include/libglbarcode-3.0/libglbarcode/lgl-barcode-render-to-cairo.h glabels-dev: /usr/share/gtk-doc/html/libglbarcode-3.0/libglbarcode-3.0-lgl-barcode-render-to-cairo.html gstreamer1.0-plugins-good-doc: /usr/share/gtk-doc/html/gst-plugins-good-plugins-1.0/gst-plugins-good-plugins-plugin-cairo.html guile-cairo-dev: /usr/include/guile-cairo/guile-cairo.h guitarix-doc: /usr/share/doc/guitarix-doc/namespacegx__cairo.html ipe: /usr/share/ipe/7.2.7/doc/group__cairo.html libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/Pango_cairo.html libcairo-ocaml-dev: /usr/share/doc/libcairo-ocaml-dev/html/type_Pango_cairo.html libcairo2-dev: /usr/include/cairo/cairo.h ...
However, if you know the file path, for example, you want to find the software package where the file is located
/usr/include/cairo/cairo.h Belong to, run:
apt-file search /usr/include/cairo/cairo.h
This will only list the packages that contain this file:
$ apt-file search /usr/include/cairo/cairo.h libcairo2-dev: /usr/include/cairo/cairo.h
In this example, the package containing the file I searched for (
apt-file can also be used to list all files included in the package (
apt-file list packagename), Perform regular expression search, etc. Check its man page (
man apt-file) And help get more information (
2. Use dpkg to find the package that provides the file (only applicable to the installed DEB package-from any source)
dpkg can also be used to find out which software package a file belongs to. It can be used faster than apt-file, because you don’t need to install anything, and there is no database to update.
However, dpkg can only search for files that belong to installed packages, so if you want to search for files in packages that are not installed on the system, use apt-file. On the other hand, dpkg can be used to find files that belong to packages that are installed without using a repository, which is a feature that is not available with apt-file.
To use dpkg to find installed DEB packages that provide files, use
--search) Flag, and then the file name (or pattern) of the package you want to see to which it belongs, as shown below:
dpkg -S filename
For example, to find out
cairo.h File belongs to, use
dpkg -S cairo.h:
$ dpkg -S cairo.h libgtk2.0-dev:amd64: /usr/include/gtk-2.0/gdk/gdkcairo.h libcairo2-dev:amd64: /usr/include/cairo/cairo.h libpango1.0-dev: /usr/include/pango-1.0/pango/pangocairo.h libgtk-3-dev:amd64: /usr/include/gtk-3.0/gdk/gdkcairo.h
Just like apt-file, this may display multiple packages containing files that contain the file name to be found. You can enter the full path of the file to get only the software package that contains that specific file. example:
$ dpkg -S /usr/include/cairo/cairo.h libcairo2-dev:amd64: /usr/include/cairo/cairo.h
In this example, the Debian package that contains the files I searched for (
libcairo2-devOther notable ways to find the package to which the file belongs are to use the online search provided by Ubuntu and Debian:
- Ubuntu: https://packages.ubuntu.com/ -Scroll down to
Search the contents o packagesAnd enter the file name you want to find, as well as the distribution (Ubuntu version) and architecture.
- Debian: https://www.debian.org/distrib/packages#search_contents -The search is similar to the search for Ubuntu, so please enter the file name, distribution and architecture to find.
For both, you will also find options to find packages that contain files with the exact same name as the entered keywords, packages that end with keywords, or packages that contain files with names that contain keywords.
Linux Mint Parcel search The website does not provide an option to search for files in packages, but you can use Ubuntu or Debian online packages to search for packages imported from Debian / Ubuntu by Linux Mint.