How to find which package contains a file in Ubuntu?

Once upon a time we faced a lot of dependency hell issues in Linux platforms. apt-get has matured enough such that this is not believable for newbies now. Kudos to Debian!

Some times we want to know which package has one particular file we are interested. In some other times we want to know the files installed by a package. To get this done, you need not to install and check.

The powerful dpkg and apt-file command line tools will do it. Here is how to get it done in Debian derivative Ubuntu.

Searching for a file with its absolute path name (full path name)

When you know the full path of the file, you can use dpkg command to find the corresponding package. The syntax is:

dpkg –search <full path of file>

In the following example console session, the /etc/gnome/defaults.list is found in desktop-file-utils package.

$ dpkg –search /etc/gnome/defaults.list
desktop-file-utils: /etc/gnome/defaults.list

Searching for a file (not knowing its path)

In some cases we won’t know the path of the file. i.e the file which belongs to a package which we have not installed. Mostly during compilation of a package, we use to face this issue of searching for a header file, library file, etc. In this scenario, apt-file tool will be handy. Here is how to get it done.


Run the following commands to get it installed and updated with latest package informations.

$ sudo apt-get install apt-file

$ sudo apt-file update

The syntax to search for a file is shown below:

$ apt-file search <filename>

The following example searches for pngconf.h file. It is noted that the pngconf.h may be a file name or part of another file name.

$ apt-file search pngconf.h

libpng12-dev: /usr/include/libpng12/pngconf.h

libpng12-dev: /usr/include/pngconf.h

plt-scheme: /usr/lib/plt/collects/plot/src/all/pngconf.h

thunderbird-dev: /usr/include/thunderbird-3.0.4/unstable/mozpngconf.h

thunderbird-dev: /usr/include/thunderbird-3.0.4/unstable/pngconf.h

xulrunner-1.9.2-dev: /usr/include/xulrunner-1.9.2.3/mozpngconf.h

xulrunner-1.9.2-dev: /usr/include/xulrunner-1.9.2.3/pngconf.h




This entry was posted in HOW-TOs and tagged , , , , . Bookmark the permalink.