Debian

How to Find the Debian Package that Provides a File

A package in Linux is a combination of different files that are installed once you install that package on your system. Sometimes, you may know the exact name and path of a file, but you want to know the package to which that file belongs. This article shows you three methods for finding the Debian package for a file.

Note: All the methods discussed in this article are performed on a Debian 10 system.

To find the Debian package for a file, use any of the three methods shown in the following sections.

Method 1: Using the “dpkg” Command

To use the “dpkg” command to find the Debian package that provides the specified file, issue the following:

$ dpkg –S PathToTheFile

When executing the above command, replace “PathToTheFile” with the exact path of the file whose respective package you want to find. We wanted to find the package that provides the file “/usr/bin/passwd” using the “dpkg” command.

The Debian package that provides the specified file in our case is “passwd,” as shown in the image below:

Method 2: Using the “dpkg-query” Command

To use the “dpkg-query” command to find the Debian package that provides the specified file, issue the following:

$ dpkg-query –S ‘PathToTheFile’

When executing the above command, replace “PathToTheFile” with the exact path of the file whose respective package you want to find. We wanted to find the package that provides the file “/usr/bin/passwd” using the “dpkg-query” command. Note that in this method, the path to the file must be given in single quotes.

The Debian package that provides the specified file in our case is “passwd,” as shown in the image below:

Method 3: Using the “apt-file” Command

To use the “apt-file” command to find the Debian package that provides the specified file, you will have to install this command first, since it is not a built-in Debian command. This command can be installed by issuing the following:

$ sudo apt-get install apt-file

When this command is installed on your Debian 10 system, it will render some messages in the terminal, as shown in the image below:

Before using this command, you will have to update your Debian 10 system, as follows:

$ sudo apt-file update

The system update will be completed after a few seconds, and the following messages will be displayed in the terminal:

Now, you can conveniently use the “apt-file” command to find the Debian package that provides the specified file in the following manner:

$ apt-file search PathToTheFile

When executing the above command, replace “PathToTheFile” with the exact path of the file whose respective package you want to find. We wanted to find the package that provides the file “/usr/bin/passwd” using the “apt-file” command.

The Debian package that provides the specified file in our case is “passwd,” as shown in the image below:

Conclusion

You can easily determine the Debian package that owns a specified file using any of the three methods shown in this article. Hence, you can figure out the origin of any file using a Debian system.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.