Find the package a file is from

A quick tip today for all Debian (and derivative) users:

Have a file on in your system that you just can’t figure out where it came from? Searching for the name in Synaptic doesn’t help? About ready to heave your weary keyboard out the window in an administrative rage? Fear not, dpkg to the rescue!

Let’s say you are trying to find out where in the world /usr/share/epiphany-browser/glade/ came into existence. You’ve checked epiphany-browser, but it’s not there. Let’s ask dpkg-query:

$ dpkg-query -S /usr/share/epiphany-browser/glade/
epiphany-browser-data: /usr/share/epiphany-browser/glade/

Okay, so it was in epiphany-browser-data. Let’s ask dpkg-query to do the reverse this time, and find all files included in that package:

$ dpkg-query -L epiphany-browser-data
# ...

A good trick I use instead of remembering dpkg-query switches is to simply add aliases to my .bashrc:

alias dpkgs="dpkg-query -S"
alias dpkgl="dpkg-query -L"

The above example could then be shortened to dpkgl epiphany-browser-data.

Not all files are managed by packages, and so this may not always get you the results you wanted. Obviously, user-created files in /home will not be from any packages, nor will most files in /etc. But it’s still a handy way to figure out where a file came from.

In one last example, you can take advantage of shell command nesting to figure out which package contains a binary:

$ dpkg-query -S `which firefox`
firefox-3.0: /usr/bin/firefox

(Those are backticks, by the way, not regular quotes.)

Avatar for jacob Jacob Peddicord -

Jacob is a web developer, student, and programmer from Ohio. He is a staff member at the Ubuntu Forums and is most likely a fanboy of the distribution. He loves to write in code and words, play video games, and rant about topics most would have abandoned long ago. Jacob uses GNOME and is never seen running stable software, much to the demise of his laptop.

Home » Articles »

Discussion: Find the package a file is from

  1. Adam Williamson (guest)

    # Posted on 30 May 2009 at 04:05 PM

    For RPM-based distros:

    rpm -qf <filename>

  2. Aksel (guest)

    # Posted on 31 May 2009 at 08:12 AM

    You can also use dlocate

    sudo apt-get install dlocate

    dlocate <filename>

    It might take some time for the index to be built.

  3. jayjay (guest)

    # Posted on 12 June 2009 at 04:23 PM

    or use apt-file :-)

  4. johnstevens (guest)

    # Posted on 23 June 2009 at 06:29 AM

    п»ї Thank you for the nice article...

Home » Articles » Find the package a file is from