Ubuntu

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)

$ dpkg -L <package_name>

You can find out which a .deb package will install files through the following simple dpkg command.

$ dpkg-deb -c /home/ubuntu/Desktop/example.deb

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.

$ dpkg --contents PACKAGENAME

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:

$ dpkg -S cairo.h

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.

$ dpkg -S /usr/include/cairo/cairo.h

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.

$ sudo apt install apt-file

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.

$ sudo apt-file update

Now that everything is up and running, we initiate the search for our required packages. This can be done through the following command.

$ apt-file list package

If you want to search for a particular filename (cairo.h in our case), you can use the command below.

$ apt-file search cairo.h

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.

$ apt-file search /usr/include/cairo/cairo.h

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.

$ man apt-file

$ apt-file --help

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 by degree, Blogger by skills who loves to write about tech, develop websites & do SEO. You can reach out to me on LinkedIn.