How to list files of a Debian package without install

295

73

This command can only list contents of installed packages,

dpkg -L PACKAGENAME

but how to list contents of a non-installed package, to preview/examine the package?

Xiè Jìléi

Posted 2009-12-14T06:49:35.120

Reputation: 14 766

Similar on Ubuntu: http://askubuntu.com/questions/32507/how-do-i-get-a-list-of-installed-files-from-a-package

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-05-12T10:56:42.273

Answers

359

dpkg -c (or --contents) lists the contents of a .deb package file (It is a front-end to dpkg-deb.)

dpkg -c package_file.deb

To work directly with package names rather than package files, you can use apt-file. (You may need to install the apt-file package first.)

sudo apt-file update        
apt-file list package_name

As stated in the first comment, apt-file lists contents for packages in your already-configured Apt repositories. It is irrelevant whether any particular package is or is not installed.

alfplayer

Posted 2009-12-14T06:49:35.120

Reputation: 4 523

5@confiq, not by my testing. I'm running 12.04.4 and it still says "E: The cache is empty. You need to run 'apt-file update' first." – Matthew Flaschen – 2014-06-28T20:48:45.370

17apt-file also needs to be updated (sudo apt-file update), and only lists contents for packages in your already-configured Apt repositories. – quack quixote – 2010-01-28T22:54:28.380

apt-file list doesn't work for me. – icando – 2014-10-10T18:24:05.017

Per @eskhool - Incorrect that apt-file update is not needed in Ubuntu...as of Ubuntu 14.04 this is still required – fixer1234 – 2014-12-18T06:42:35.513

To show the package's description and controls, ar p NAME.deb control.tar.gz | tar xOvz ./control – eel ghEEz – 2015-03-19T19:50:50.450

@icando apt-file find works, but apt-file list does not. Strange program. – user1742529 – 2020-02-09T06:57:03.913

1@quackquixote: In Ubuntu 12.04 it's automatic – confiq – 2012-05-13T10:43:48.367

1dpkg -c nice! – d-_-b – 2012-10-15T09:57:42.587

2The Apt-file answer assumes that your package is coming from a configured repository instead of a .deb file you have downloaded separately. The original question is ambiguous though. – Zoredache – 2013-01-15T23:27:43.353

58

Use --contents instead of -L:

dpkg --contents PACKAGENAME

When used in this manner, dpkg acts as a front-end to dpkg-deb, so use man dpkg-deb to see all the options.

You can also use an archive browser to view the package contents.

quack quixote

Posted 2009-12-14T06:49:35.120

Reputation: 37 382

Get the .deb file with apt-get download, e.g.: apt-get download apt-file; dpkg -c apt-file*.deb; rm apt-file*.deb. – reinierpost – 2016-09-22T09:33:12.680

3This answer is wrong. You have to have the package installed first. If you don't have it installed, then you don't have a .deb file. – Neil – 2012-05-01T02:14:42.893

This command works for me. For example, I downloaded google-chrome-stable_current_amd64.deb from Google. Then issued the command: dpkg --contents google-chrome-stable_current_amd64.deb and it listed out all the files it will install (mostly to /opt/google/chrome), none of which are currently installed on my system as I type this. (I'm running Xubuntu 11.10 if that matters.) – quux00 – 2012-08-04T21:11:07.347

11@Neil, the answer is not wrong. Just because you have a deb file, doesn't mean it's installed. apt-file needs the entire build-essential package. O.O – d-_-b – 2012-10-15T10:00:34.957

Works great for me, and does not require the installation of the full build-essential package, as required by the accepted answer. – plang – 2013-06-13T05:58:37.953

2This doesn't work unless I installed it first and then uninstall it. – Xiè Jìléi – 2009-12-15T14:07:39.110

3it should work fine if you give it a .deb file as an argument (instead of PACKAGENAME, give it PACKAGE-DEB-FILE). – quack quixote – 2009-12-15T22:11:53.757

23

dpkg --contents will let you look at the uninstalled package. If the .deb is not on your system yet, do

apt-get --download-only install pkgname

The package will get downloaded to /var/cache/apt/archives but not installed.

Rudedog

Posted 2009-12-14T06:49:35.120

Reputation: 1 560

4Can I just list the contents without download it? If I'm on a very slow connection, and if the package is too large to download. If the .deb file has a file header where contents list goes, I guess download the whole package maybe not necessary. Is this possible? – Xiè Jìléi – 2009-12-15T14:06:52.403

15

The best way would be to browse directly the package repository:

http://packages.debian.org/[distro name]/all/[package name]/filelist

Example:

http://packages.debian.org/wheezy/all/transmission-common/filelist

baldoz

Posted 2009-12-14T06:49:35.120

Reputation: 151

And to avoid leaving the terminal, you can use e.g. lynx -dump -nolist http://packages.debian.org/wheezy/all/transmission-common/filelist | grep ^/ (provided you have lynx installed). – Ruslan – 2018-08-17T11:40:22.567

8

I took @baldoz's http idea and generalized it for Ubuntu and Debian, added a little sed and wrapped it in a bash function one-liner:

function deb_list () { curl -s $(lsb_release -si | sed -e 's Ubuntu https://packages.ubuntu.com ' -e 's Debian https://packages.debian.org ')/$(lsb_release -sc)/all/$1/filelist | sed -n -e '/<pre>/,/<\/pre>/p' | sed -e 's/<[^>]\+>//g' -e '/^$/d'; }

Usage:

$ deb_list curl
/usr/bin/curl
/usr/share/doc/curl/changelog.Debian.gz
/usr/share/doc/curl/copyright
/usr/share/doc/curl/NEWS.Debian.gz
/usr/share/man/man1/curl.1.gz

Same function on multiple lines:

function deb_list () {
    curl -s $(lsb_release -si \
                | sed -e 's Ubuntu https://packages.ubuntu.com ' \
                      -e 's Debian https://packages.debian.org '
              )/$(lsb_release -sc)/all/$1/filelist \
      | sed -n -e '/<pre>/,/<\/pre>/p' \
      | sed -e 's/<[^>]\+>//g' -e '/^$/d';
}

Explained:

  1. lsb_release -si returns "Ubuntu" or "Debian" replace that with the base url https://packages.ubuntu.com or https://packages.debian.org
  2. lsb_Release -sc returns the codename (e.g. "trusty", "sid", etc) use that to build the full URL: https://packages.ubuntu.com/trusty/all/curl/filelist
  3. Fetch that URL with curl and pipe the html through three sed commands. First captures only the file list (what's between <pre> and </pre> tags); second strips out any html tags; third removes any blank lines.

Note: It doesn't search PPAs, alternate apt sources repos and only queries official packages available for the release of debian/ubuntu you are running.

notpeter

Posted 2009-12-14T06:49:35.120

Reputation: 899

Do i need ruby to run it? – Anwar – 2015-07-01T07:03:13.280

1@Anwar, I'd initially used Ruby because I was lazy and multiline regexes suck in sed/awk/grep. But I've rewritten it to use two sed commands, no Ruby required. – notpeter – 2015-07-01T16:01:02.850

Nice! This is the answer I was looking for – Anwar – 2015-07-01T16:37:56.070

5

For all those people who might still googling this issue at Jan 2017, you can have some cool stuff with recent versions of apt and dpkg in Debian 8.5 without downloading anything.

List Contents of Deb File Without Download:

First locate the full url of the deb file :

root@debian:apt-get --print-uris download yade
'http://httpredir.debian.org/debian/pool/main/y/yade/yade_2016.06a-7_amd64.deb' yade_2016.06a-7_amd64.deb 1621148 SHA256:26c0d84484a92ae9c2828edaa63243eb764378d79191149970926aa3ec40cdd4

PS: --print-uris switch prints the url of deb package but deb is not downloaded.

Then display contents of deb package without downloading it:

root@debian:curl -sL -o- "http://httpredir.debian.org/debian/pool/main/y/yade/yade_2016.06a-7_amd64.deb" |dpkg-deb -c /dev/stdin
drwxr-xr-x root/root         0 2016-12-10 22:18 ./
drwxr-xr-x root/root         0 2016-12-10 22:18 ./usr/
drwxr-xr-x root/root         0 2016-12-10 22:18 ./usr/bin/
-rwxr-xr-x root/root     13184 2016-12-10 22:18 ./usr/bin/yade
.........................more files listed bellow ......................

PS: Same result can be achieved with

root@debian:dpkg -c <(curl -sL -o- "http://httpredir.debian.org/debian/pool/main/y/yade/yade_2016.06a-7_amd64.deb")

Extract a file from the above deb package , without download.
For example we want to read man page of package yade without installing this package and without even downloading the deb package.

Filename of man page inside deb package as advised by dpkg -c is ./usr/share/man/man1/yade.1.gz

To read man page on the fly:

root@debian:curl -sL -o- "http://httpredir.debian.org/debian/pool/main/y/yade/yade_2016.06a-7_amd64.deb" |dpkg-deb --fsys-tarfile /dev/stdin |tar -xO ./usr/share/man/man1/yade.1.gz |man /dev/stdin

man page is displayed correctly using man application.

PS: Above pipes does not work with ar command.

root@debian:apt --version --> apt 1.4~beta2 (amd64)
root@debian:dpkg --version --> Debian 'dpkg' package management program version 1.18.18 (amd64).
root@debian:man --version --> man 2.7.6.1
root@debian:tar --version --> tar (GNU tar) 1.29

George Vasiliou

Posted 2009-12-14T06:49:35.120

Reputation: 171

This description works for systems that use only "apt" and don't have the older "apt-x" commands available! – Jon Watte – 2019-08-09T20:11:23.277

2

Try:

apt-get download packages-name
dpkg --contents *.deb

readanon

Posted 2009-12-14T06:49:35.120

Reputation: 21

1

Seems it's not possible before installing it first or extracting the list from .deb file.

Try the following command:

dpkg --contents <(curl -s $(apt-get install --yes --no-download --reinstall --print-uris language-pack-en | tail -n1 | grep -o "http[^']\+"))

Change language-pack-en with your package name.

It basically reads .deb file extracted via curl and run dpkg --contents FILE on it.


You can also check the content without downloading the package file.

So if you know the URL of .deb file, the following shell command will list all the package files:

dpkg -c <(curl -sL "http://httpredir.debian.org/debian/pool/main/a/avis/avis_1.2.2-4_all.deb")

Curl params: -s - silent, -L - follow moved links.

If you don't know the URL, fetch by: apt --print-uris, e.g.

apt --print-uris install avis | grep avis

kenorb

Posted 2009-12-14T06:49:35.120

Reputation: 16 795