Find the package a file is from

  • May 29, 2009
  • Avatar for jacob
    Jacob
    Peddicord

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/epiphany.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.glade
epiphany-browser-data: /usr/share/epiphany-browser/glade/epiphany.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
/usr/share/epiphany-browser
/usr/share/epiphany-browser/components
/usr/share/epiphany-browser/components/epiphany.xpt
/usr/share/epiphany-browser/art
/usr/share/epiphany-browser/chrome
# ...

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

Home » Articles »