Table of Contents
Ubuntu - Packages - Determine which package a file belongs to
Objective
Given the pathname to a file on a Debian-based system, to determine the name of the package that file belongs to
Scenario
Suppose that, for reasons unknown, the file /usr/lib/libgtk-1.2.so.0.9.1 has become corrupted.
You wish to correct this problem by reinstalling the package that contains the corrupted file, but in order to do this you need to know the name of that package.
Method
The package name can be obtained using the -S option of the dpkg command:
dpkg -S /usr/lib/libgtk-1.2.so.0.9.1
The argument is a pattern that matches all or part of the pathname you want to search for. It may contain wildcards such as ? and *, with similar (but not identical) semantics to those of a glob pattern.
Alternatives
Searching the repository
The method described above is only applicable to files that are installed locally on the machine that you are querying. Neither dpkg nor apt has the ability to search for files that have not been installed because the index provided by the package repository does not list the files included in each package. Individual packages contain this information, but they are not accessible to apt unless and until they have been downloaded.
The package repository already has a copy of each package, so in principle it has all of the information needed to perform a global search for a pathname. At least two major distributions (Debian and Ubuntu) provide this facility, and they do so at the following URLs:
Debian | http://packages.debian.org/ |
Ubuntu | http://packages.ubuntu.com/ |
In both cases the search is limited to recent releases only.