126

How do I get a list of files that were or will-be installed when I apt-get a package? Conversely, can I find what package(s) caused a particular file to be installed?

David Nehme
  • 1,756
  • 4
  • 14
  • 13
  • Similar on SU http://superuser.com/questions/82923/how-to-list-files-of-a-debian-package-without-install on Ubuntu: http://askubuntu.com/questions/32507/how-do-i-get-a-list-of-installed-files-from-a-package – Ciro Santilli OurBigBook.com May 12 '15 at 10:56
  • Both ubuntu and debian have web for this, for example https://packages.ubuntu.com/focal/amd64/tldr/filelist – Rick Jun 21 '22 at 08:29

4 Answers4

174

Note: in the following commands, a command beginning with 'root#' means it needs to be run as root.

To find which files were installed by a package, use dpkg -L:

$ dpkg -L $package

apt-file can tell you which files will be installed by a package before installing it:

root# apt-get install apt-file
root# apt-file update
$ apt-file list $package

Or if you have the package as a .deb file locally already, you can run dpkg on it:

$ dpkg --contents $package.deb

To find which package provides a file that is already on your system, use:

$ dpkg -S /path/to/file

To find which package provides a file that is not currently on your system, use apt-file again:

$ apt-file search /path/to/file
slm
  • 7,355
  • 16
  • 54
  • 72
raphink
  • 11,337
  • 6
  • 36
  • 47
  • 10
    Keep in mind that while this will get you most of what you need it will not give you everything. Several packages create configuration files as part of their setup scripts. These files will not be reported by dpkg. – Zoredache Dec 23 '09 at 17:33
  • `$ dpkg -L package` not `$ dpkg -L $package` putting the $ in front of the package names returns an error – Alecz Jan 14 '17 at 21:50
  • 2
    The dollar is meant to be understood as a variable, meaning you need to replace `$package` with the actual name of the package. – raphink Jan 15 '17 at 23:37
  • 1
    conffiles of a package (if any) are listed by command `dpkg --status $package`. For the reverse operation use `grep $filename /var/lib/dpkg/info/*.conffiles`. – Uwe Geuder Mar 08 '18 at 17:38
  • 1
    bit late Q - - what does `sudo apt-file update` do ?? – samshers Aug 21 '20 at 10:01
  • 1
    @samshers, `apt-file update` command populates the db which `apt-file` uses for searches. – Victor Yarema Oct 28 '20 at 19:49
  • what if you don't have apt-file? – confiq Dec 18 '20 at 10:16
  • 1
    @confiq if you don't have apt-file, run `sudo apt-get -y install apt-file` then run `sudo apt-file update`. After that you can use the tool as described above. – Speeddymon Jan 10 '22 at 18:24
  • I find `apt-file list $package` the most useful. `dpkg -L $package` lists directories. Thanks! – Rick Jun 21 '22 at 08:28
4
dpkg -S /path/to/file/in/question

As far as I'm concerned, dpkg is the low-level tool that apt-get depends on.

Olaf
  • 908
  • 5
  • 7
  • Yes, dpkg is the command that adds and removes software and files from you mcomputer. apt (incl. Apt-get, aptitude, synaptic, etc.) is the programme that calls dpkg – Amandasaurus May 09 '10 at 12:06
  • It can be done with some creative piping from apt-get though, see my answer below :) – linuxgeek Jan 11 '22 at 05:24
3

Here is a function that should do it for you without the need to downloading the package to disk.

apt_list () 
{ 
    local packages=("$@");
    for pkg in $(seq 0 1 $((${#packages[@]}-1)));
    do
        echo -e "\n#### ${packages[$pkg]} ####\n";
        apt-get download -o Dir::Cache::archives="./" --print-uris ${packages[$pkg]} | awk -F\' '{print $2}' | xargs -I '{}' curl -skL '{}' | dpkg-deb -c /dev/stdin | perl -ne 's,(:\d\d )[.]/,$1/,g;print';
        echo;
    done
}

Then use apt_list <package name1> [package name 2]

e.g. apt_list curl wget

As for reverse checking files from packages apt-file would be the best bet.

linuxgeek
  • 61
  • 5
2

If you have installed dlocate, you can use dlocate -L the same way as dpkg -L. It works exactly the same in this case, but has a number of other options.

Karol
  • 323
  • 2
  • 9