How to List Files of Deb Package Before Installing

The typical question before installing a new deb package on our system is that what are the actual files were installed and where new files are located. The critical situation is raised when an unwanted file is replaced which you never wanted to replace it. So today in this tutorial I'll be focusing on steps where you as system admin can take look at files before installing package and make sure you are safe. We'll be using Ubuntu 18.04 for this article and it should work for all other Linux distros that support deb packages.

To list contents of a non-installed package, we will need a .deb package. Lets download an Ubuntu Package for our testing.

Let's take 'curl' package as an example.

To download curl:

$ sudo wget http://archive.ubuntu.com/ubuntu/pool/main/c/curl/curl_7.58.0-2ubuntu3_amd64.deb
$ ls

curl_7.58.0-2ubuntu3_amd64.deb DEBIAN Desktop Documents Downloads examples.desktop Music Pictures Public Templates Videos

dpkg Packaging

We can grab information about a package by 'dpkg -I '... But It won't tell us the contents. dpkg is a package manager for Debian based systems.

To see contents, use option '--contents' or '-c' for dpkg command.

$ dpkg -c curl_7.58.0-2ubuntu3_amd64.deb

## OR ##

dpkg-deb -c curl_7.58.0-2ubuntu3_amd64.deb
drwxr-xr-x root/root         0 2018-03-15 17:50 ./
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/bin/
-rwxr-xr-x root/root    223304 2018-03-15 17:50 ./usr/bin/curl
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/share/
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/share/doc/
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/share/doc/curl/
-rw-r--r-- root/root     10955 2018-01-25 01:57 ./usr/share/doc/curl/copyright
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/share/man/
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/share/man/man1/
-rw-r--r-- root/root     38989 2018-03-15 17:50 ./usr/share/man/man1/curl.1.gz
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/share/zsh/
drwxr-xr-x root/root         0 2018-03-15 17:50 ./usr/share/zsh/vendor-completions/
-rw-r--r-- root/root     12851 2018-03-15 17:50 ./usr/share/zsh/vendor-completions/_curl
lrwxrwxrwx root/root         0 2018-03-15 17:50 ./usr/share/doc/curl/NEWS.Debian.gz -> ../libcurl4/NEWS.Debian.gz
lrwxrwxrwx root/root         0 2018-03-15 17:50 ./usr/share/doc/curl/changelog.Debian.gz -> ../libcurl4/changelog.Debian.gz

Above we can see details of contents of given package. Cons are we must have downloaded respected .deb package.

To find which package a specific .deb file came from:

$ sudo dpkg -S curl
libcurl3:amd64: /usr/share/doc/libcurl3/NEWS.Debian.gz
libcurl3-gnutls:amd64: /usr/share/doc/libcurl3-gnutls/changelog.Debian.gz
bash-completion: /usr/share/bash-completion/completions/curl
libpython2.7-stdlib:amd64: /usr/lib/python2.7/macurl2path.py
libcurl3:amd64: /usr/share/doc/libcurl3
python3-pycurl: /usr/share/doc/python3-pycurl
libcurl3:amd64: /usr/lib/x86_64-linux-gnu/libcurl.so.4.4.0
libcurl3-gnutls:amd64: /usr/share/doc/libcurl3-gnutls/copyright
libcurl3-gnutls:amd64: /usr/share/doc/libcurl3-gnutls/NEWS.Debian.gz
gnupg: /usr/lib/gnupg/gpgkeys_curl
python3-pycurl: /usr/lib/python3/dist-packages/curl
libcurl3:amd64: /usr/share/lintian/overrides/libcurl3
python3-pycurl: /usr/share/doc/python3-pycurl/copyright
libcurl3:amd64: /usr/share/doc/libcurl3/changelog.Debian.gz
libpython3.5-stdlib:amd64: /usr/lib/python3.5/macurl2path.py
python3-pycurl: /usr/share/doc/python3-pycurl/changelog.Debian.gz
libcurl3:amd64: /usr/share/doc/libcurl3/copyright
libcurl3:amd64: /usr/lib/x86_64-linux-gnu/libcurl.so.4
libcurl3:amd64: /usr/lib/x86_64-linux-gnu/libcurl.so.3
python3-pycurl: /usr/lib/python3/dist-packages/curl/__init__.py
python3-pycurl: /usr/lib/python3/dist-packages/pycurl.cpython-35m-x86_64-linux-gnu.so
libcurl3-gnutls:amd64: /usr/share/lintian/overrides/libcurl3-gnutls
libcurl3-gnutls:amd64: /usr/share/doc/libcurl3-gnutls
python3-pycurl: /usr/lib/python3/dist-packages/pycurl-7.43.0.egg-info
libcurl3-gnutls:amd64: /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4
libcurl3-gnutls:amd64: /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.3
libcurl3-gnutls:amd64: /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4.4.0
....

With the option -L we ask dpkg to list the content of an installed package by providing it the package name.

To list files installed by a package:

$ sudo dpkg -L curl
/.
/usr
/usr/bin
/usr/bin/curl
/usr/share
/usr/share/doc
/usr/share/doc/curl
/usr/share/doc/curl/copyright
/usr/share/zsh
/usr/share/zsh/vendor-completions
/usr/share/zsh/vendor-completions/_curl
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/curl.1.gz
/usr/share/doc/curl/changelog.Debian.gz
/usr/share/doc/curl/NEWS.Debian.gz
...

Listing files using apt-file

"apt-file" a software package that lists the contents of packages in your repositories and allows you to search for a particular file among all available packages.

To install 'apt-file':

$ sudo apt install apt-file
$ sudo apt-file update

Now list contents of any package:

$ sudo apt-file list

Example 1:

$ sudo apt-file list curl
curl: /usr/bin/curl
curl: /usr/share/doc/curl/NEWS.Debian.gz
curl: /usr/share/doc/curl/changelog.Debian.gz
curl: /usr/share/doc/curl/copyright
curl: /usr/share/man/man1/curl.1.gz
curl: /usr/share/zsh/vendor-completions/_curl

Example 2:

$ sudo apt-file list ssh
ssh: /usr/share/doc/ssh/NEWS.Debian.gz
ssh: /usr/share/doc/ssh/changelog.Debian.gz
ssh: /usr/share/doc/ssh/copyright
ssh: /usr/share/lintian/overrides/ssh

Below is the best way 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

To extract the files that some_package.deb into a directory:

$ sudo mkdir some_dir
$ sudo dpkg -x some_package.deb some_dir

Example:
For package ‘curl’

$ sudo mkdir curl_extracts
$ sudo dpkg -x curl_7.58.0-2ubuntu3_amd64.deb curl_extracts
$ tree curl_extracts
curl_extracts/
└── usr
	├── bin
	│   └── curl
	└── share
    	├── doc
    	│   └── curl
    	│   	├── changelog.Debian.gz -> ../libcurl4/changelog.Debian.gz
    	│   	├── copyright
    	│   	└── NEWS.Debian.gz -> ../libcurl4/NEWS.Debian.gz
    	├── man
    	│   └── man1
    	│   	└── curl.1.gz
    	└── zsh
        	└── vendor-completions
            	└── _curl

9 directories, 6 files

To extract the control data (package script, metadata, etc.) that some_package.deb into a directory:

$ sudo mkdir some_dir
$ sudo dpkg -e some_package.deb some_dir

Example:
For package ‘curl’

$ sudo mkdir curl_control_data
$ sudo dpkg -x curl_7.58.0-2ubuntu3_amd64.deb curl_control_data
$ tree curl_control_data
curl_control_data/
├── control
└── md5sums

0 directories, 2 files

ar vx command

The GNU ar program builds, modifies, and extracts from archives. A single file holding collection of other files in a structure that makes possible to retrieve the original individual files (called members of the archive) are called Archive.

Checking for the contents by extracting directly .deb file itself.

$ sudo ar vx curl_7.58.0-2ubuntu3_amd64.deb

This command will extract .deb file and generate following 3 outputs.

x - debian-binary
x - control.tar.xz
x - data.tar.xz

GNU/tar or BSD/tar is an archiving program designed to store and extract files from an archive file known as a tar file. You can create a tar file or compressed tar file (.tar). However, sometimes you need to list the contents of tar or tar.gz file on screen before extracting all files.
Lets extract 3rd file i.e. data.tar.xz to see contents of .deb file.

where,

t: List the contents of an archive.
v: Verbosely list files processed (display detailed information).
z: Filter the archive through gzip so that we can open compressed (decompress) .gz tar file.
J: Filter archive through bzip2, use to decompress .bz2 files.
f filename: Use archive file called filename.

$ tar -xvJf data.tar.xz
./
./usr/
./usr/bin/
./usr/bin/curl
./usr/share/
./usr/share/doc/
./usr/share/doc/curl/
./usr/share/doc/curl/copyright
./usr/share/man/
./usr/share/man/man1/
./usr/share/man/man1/curl.1.gz
./usr/share/zsh/
./usr/share/zsh/vendor-completions/
./usr/share/zsh/vendor-completions/_curl
./usr/share/doc/curl/NEWS.Debian.gz
./usr/share/doc/curl/changelog.Debian.gz

All above where steps where you can look into the package, hope you find this tutorial useful. Please comment other methods that you know and keep reading the upcomming tutorial.

Yash Vasa 2:10 am

About Yash Vasa

Yash, a passionate Linux System Administrator and tech enthusiasts. He drive immerse gratification in conducting research on Industrial IoT platforms and keeping up to date with the latest technology world. He believe that combination of brilliant mind, gold ideas & utter disregards for what is possible can & will change the world.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.