How to list files of a Debian package without install
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?
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.
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.
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.
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
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:
- lsb_release -si returns "Ubuntu" or "Debian" replace that with the base url
https://packages.ubuntu.com
orhttps://packages.debian.org
- 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
- 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.