How do I find out which package owns a file?

101

19

How do I find out what Debian package a file came from?

A Student at a University

Posted 2010-08-23T10:23:55.360

Reputation: 391

Answers

44

There are several utilites in Debian which perform this task; check this page for a description. I'll mention two of them, apt-file and dlocate.

apt-file searches its internal cache, thus allowing you to not install all the packages you want to search. Below you will find more detailed guide.

dlocate is a fast alternative to dpkg -L (the command that lists package contents), and as so, it searches only installed packages. Search is performed by dlocate -S file.name.

Also you can search packages online using packages.debian.org server (the Search the contents of packages section).


Installing and using apt-file

It's a good idea to update first:

sudo apt-get update

See what apt-file is for:

apt-cache show apt-file

Install it:

sudo apt-get install apt-file

Read data from repositories (this works also without sudo but creates user's cache then; with sudo the cache is system-wide):

sudo apt-file update

Perform search. In this example we want to know in which package xrandr executable is:

apt-file search xrandr

It lists many packages with unxrandr, lxrandr.mo or source_lxrandr.py. Not very useful in our case. More clever search:

apt-file search -x /xrandr$

($ denotes end of line). Example output:

bash-completion: /usr/share/bash-completion/completions/xrandr
x11-xserver-utils: /usr/bin/xrandr

The first result doesn't look like executable, the second one does. We can investigate further. Run:

apt-cache show x11-xserver-utils

Bingo! This is the package.

whitequark

Posted 2010-08-23T10:23:55.360

Reputation: 14 146

The first link in this answer (http://www.debianhelp.co.uk/findfile.htm) seems to be defunct now.

– rogpeppe – 2018-01-23T14:33:33.270

130

user@host:~$ dpkg-query -S /bin/bash 
bash: /bin/bash

Where bash is the package name.

A Student at a University

Posted 2010-08-23T10:23:55.360

Reputation: 391

4This answer is far better than the accepted one! – Bex – 2018-10-23T06:52:55.920

Correct. It's unfortunate that the "accepted answer" gets a green checkmark, which is a mark that also conveys "correct answer". In this case, the accepted answer misses on dpkg-query -S AND it sends you down the wrong path of installing optional packages.. – Scott Prive – 2019-09-13T18:56:05.260

45

Another alternative:

$ dpkg -S /bin/bash
bash: /bin/bash

On my Ubuntu at least, both seem to be in the dpkg package, so no real advantage to any specific one...

Gert van den Berg

Posted 2010-08-23T10:23:55.360

Reputation: 538

15

Installation generated files will not be found by dpkg -S, as mentioned at: https://askubuntu.com/a/667227/52975

For example, /bin/nc appears when you install the package netcat-openbsd.

But upon:

dpkg -S /bin/nc

we get dpkg-query: no path found matching pattern /bin/nc.

This happens because /bin/nc is generated by the update-alternatives call in the postinst script that gets run after installation.

It works like this because another version of /bin/nc is provided by the netcat-traditional package.

I don't think there is a general way of finding such generated files. In the specific case of alternative symlinks, we can just follow the link with readlink -f:

dpkg -S "$(readlink -f /bin/nc)"

Ciro Santilli 新疆改造中心法轮功六四事件

Posted 2010-08-23T10:23:55.360

Reputation: 5 621

2

Not being familiar with Debian, I was baffled when I tried this:

kearnsp@xubuntuvb:~$ dpkg -S /usr/bin/vncviewer
dpkg-query: no path found matching pattern /usr/bin/vncviewer
kearnsp@xubuntuvb:~$ 

A bit of investigation and I found the package:

kearnsp@xubuntuvb:~$ ls -l /usr/bin/vncviewer
lrwxrwxrwx 1 root root 27 May 28 15:49 /usr/bin/vncviewer -> /etc/alternatives/vncviewer
kearnsp@xubuntuvb:~$ ls -l /etc/alternatives/vncviewer
lrwxrwxrwx 1 root root 20 May 28 15:49 /etc/alternatives/vncviewer -> /usr/bin/xvnc4viewer
kearnsp@xubuntuvb:~$ dpkg -S /usr/bin/xvnc4viewer
xvnc4viewer: /usr/bin/xvnc4viewer
kearnsp@xubuntuvb:~$ 

Philip Kearns

Posted 2010-08-23T10:23:55.360

Reputation: 825