How to extract files from Debian package archive DEB

Very useful tool to extract files from Debian package archive DEB (*.deb) is ar command. First, let’s download a sample debian package hello_2.10-1_amd64.deb:

$ wget http://ftp.us.debian.org/debian/pool/main/h/hello/hello_2.10-1_amd64.deb

Now, that we have downloaded our sample Debian package we can use ar command to list its content. This can be achieved by t option:

$ ar t hello_2.10-1_amd64.deb 
debian-binary
control.tar.gz
data.tar.xz

At this stage we have only listed package content and now files have been extracted yet. To extract each individual files listed above use x option and supply desired file name as an argument. For example the below ar command will extract data.tar.xz file from selected debian package:

$ ls
hello_2.10-1_amd64.deb
$ ar x hello_2.10-1_amd64.deb data.tar.xz
$ ls
data.tar.xz  hello_2.10-1_amd64.deb

Depending on the compression method you can further decompresses give archive content. For XZ compressed tarball use:

$ tar xvJf data.tar.xz

and for Gzip compressed tarball use:

$ tar xvzf data.tar.xz