How to find which package a binary file belongs to on Debian/Ubuntu

If you are managing software on Debian/Ubuntu using apt-get package management, there may be cases where you want to remove or upgrade a software package that contains an existing binary file on your system. So given an existing binary file (e.g., /usr/lib/postgresql/8.4/bin/postgres), how can you find out which package provides the binary file?

This is when apt-file can help you, which is a command-line utility developed for that very purpose. First, install apt-file as follows.

$ sudo apt-get install apt-file
$ sudo apt-file update

In order to find out which package "/usr/lib/postgresql/8.4/bin/postgres" belongs to, do the following.

$ sudo apt-file search /usr/lib/postgresql/8.4/bin/postgres
postgresql-8.4: /usr/lib/postgresql/8.4/bin/postgres

The above output tells you that the binary file comes from a package called postgresql-8.4.

To remove the found package, as well as its dependencies that were installed along with it but are no longer used by anything else on the system, do the following.

$ sudo apt-get autoremove postgresql-8.4

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

Leave a comment

Your email address will not be published. Required fields are marked *