Inspecting and extracting Debian package contents | Packagecloud Blog (2024)

tl;dr

This post covers how to list and extract the contents of a Debian package. There will be examples used to show how to list the contents of debian packages that are installed and not-installed on a system, as well as, how to extract the debian control information and program files.

Related Post

Inspecting and extracting RPM package contents

What is a Debian package?

A debian package is a Unixar archivethat includes two tar archives: one containing the control information and another with the program data to be installed.

View contents of a Debian package usingdpkg

The debian package managerdpkgcomes with a utility to view the contents of a package. Assuming you have the actual debian package, the following command will list its contents:

$ dpkg -c ./path/to/test.deb

For example:

$ dpkg -c ./test_2.0.0_amd64.debdrwxr-xr-x root/root 0 2015-06-27 19:00 ./drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/bin/-rwxr-xr-x root/root 44790352 2015-06-27 19:00 ./usr/bin/testdrwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/share/drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/share/doc/drwxr-xr-x root/root 0 2015-06-27 19:00 ./usr/share/doc/test/-rw-r--r-- root/root 148 2015-06-27 18:45 ./usr/share/doc/test/changelog.gz-rw-r--r-- root/root 33 2015-06-27 18:44 ./usr/share/doc/test/copyright

As you can see in the example above, the package will install an executable binary calledtestinto/usr/bin/and supporting documentation will be dropped into/usr/share/.

Extract files from a Debian package

Using thearcommand

A debian package is just anararchive. To extract data from a deb package, use the commandarwith the-xflag:

$ ar -x ./test_2.0.0_amd64.deb$ lscontrol.tar.gz data.tar.gz debian-binary test_2.0.0_amd64.deb

The files extracted from the deb package arecontrol.tar.gzdata.tar.gzanddebian-binary. These are the control files and package data along with thedebian-binaryfile which contains the version string of the package.

Extract files fromcontrol.tar.gzanddata.tar.gzusingtar

Extracting files fromtararchives is straightforward, using the-xzfflags to extract to the current working directory:

Extracts the following files:

control md5sums

The program files are located in thedata.tar.gzarchive. Extracting this archive will effectively pull all the program files into the current working directory, in this case theusr/directory:

$ tar -xzf data.tar.gz$ lscontrol control.tar.gz data.tar.gz debian-binary md5sums test_2.0.0_amd64.deb usr$ ls usr/bintest

Usingdpkg-deb

To extract files from a debian package, use the following command:

$ dpkg-deb -x ./path/to/test.deb ./path/to/destination

For example:

$ dpkg-deb -x ./test_2.0.0_amd64.deb .$ file ./usr/bin/testusr/bin/test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x32b2d15656286b7b0e39ba1768be7767a0e7e9e8, stripped

This command extracts the contents of the package (without installing it) into the./path/to/destinationdirectory. The./path/to/destinationdirectory will be created if necessary, and the proper permissions given to match the contents of the package. The command can also be written as:

$ dpkg -x ./test_2.0.0_amd64.deb .

NOTEsimply extracting the packages to the root directory will NOT ensure a correct installation. Please usedpkgorapt-getto install packages.

Extractcontrolinformation from a Debian package usingdpkg-deb

To extract the control section from a debian package, use thedpkgcommand with the-eoption. This will extract the control files for a package into the specified directory:

$ dpkg -e ./test_2.0.0_amd64.deb$ lscontrol md5sums postinst postrm preinst prerm$ cat ./DEBIAN/md5sumsaff2ef681a6f055bb1b3c524520d9542 usr/bin/testc95b234e1d551b6198b5e375a61e2441 usr/share/doc/test/changelog.gz1699fdbd753f1bc26e6fcb312b26b4b7 usr/share/doc/test/copyright

What arepreinst,postinst,prermandpostrmfiles?

Thepreinst,postinst,prerm, andpostrmfiles are scripts that will automatically execute before or after a package is installed or removed. These scripts are part of the control section of a Debian package.

$ dpkg -e ./test_2.0.0_amd64.deb$ lscontrol md5sums postinst postrm preinst prerm$ cat ./DEBIAN/postinst#!/bin/sh# This is an example script that does nothing...exit 0

Usingapt-fileto view the contents of debian packages on remote repositories

It can be helpful to view the contents of packages that aren’t downloaded or installed on your the system. If you’ve configured an apt repository (for example apackagecloud repo) you can useapt-fileto list the contents of a package in that repository without fetching or installing the package.

Make sureapt-fileis installed on your system:

$ apt-get install apt-file

Before usingapt-fileyou have to make sure that you’ve updated it with the repositories configured on the system. To updateapt-filerun the following command:

$ apt-file update

Example output (using a packagecloud repo):

$ apt-file updateDownloading complete file https://packagecloud.io/armando/test/ubuntu/dists/precise/Contents-amd64.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 90 100 90 0 0 251 0 --:--:-- --:--:-- --:--:-- 251

After the update you can list package contents using the following command:

$ apt-file list <packagename>

For example:

$ apt-file list testtest=2.0.0: /usr/bin/testtest=2.0.0: /usr/share/doc/test/changelog.gztest=2.0.0: /usr/share/doc/test/copyright

Note that theapt-filecommand takes the name of a package that exists in the repository and not the file path to a debian package. It will search for packages by name from the apt contents metadata.

Conclusion

Understanding how packages interact with the systems they’re installed on can be helpful in day-to-day operations. A Debian package is comprised of anararchive containing twotararchives, and by knowing this, we can extract data using tools we’re familiar with(arandtar). We can also use the Debian tools provided to extract and inspect debian package contents without having to manually deconstruct the Debian archive.

Set up your own package repository.

Fast, reliable, and secure software starts here.

Try Packagecloud

Inspecting and extracting Debian package contents | Packagecloud Blog (1)

Inspecting and extracting Debian package contents | Packagecloud Blog (2024)
Top Articles
Memo To Congress: "Buy Land, They Ain't Making Any More Of It"
Controversy Unleashed: Genshin Impact, Hoyoverse and the Mujin Conundrum
Foxy Roxxie Coomer
Duralast Gold Cv Axle
Truist Bank Near Here
Is pickleball Betts' next conquest? 'That's my jam'
Chase Bank Operating Hours
Bucks County Job Requisitions
Los Angeles Craigs List
Gwdonate Org
Tracking Your Shipments with Maher Terminal
Shreveport Active 911
Kris Carolla Obituary
2016 Ford Fusion Belt Diagram
Gon Deer Forum
Bitlife Tyrone's
Overton Funeral Home Waterloo Iowa
Driving Directions To Bed Bath & Beyond
Clear Fork Progress Book
라이키 유출
Tygodnik Polityka - Polityka.pl
A Biomass Pyramid Of An Ecosystem Is Shown.Tertiary ConsumersSecondary ConsumersPrimary ConsumersProducersWhich
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
Cpt 90677 Reimbursem*nt 2023
Craigslist Ludington Michigan
Pixel Combat Unblocked
Tottenham Blog Aggregator
Pfcu Chestnut Street
Metro By T Mobile Sign In
Graphic Look Inside Jeffrey Dresser
2016 Honda Accord Belt Diagram
Does Iherb Accept Ebt
Synchrony Manage Account
Myql Loan Login
Mcgiftcardmall.con
2008 DODGE RAM diesel for sale - Gladstone, OR - craigslist
Paperless Employee/Kiewit Pay Statements
Anhedönia Last Name Origin
Amc.santa Anita
Strange World Showtimes Near Century Stadium 25 And Xd
Port Huron Newspaper
Tacos Diego Hugoton Ks
Phmc.myloancare.com
Dying Light Mother's Day Roof
Das schönste Comeback des Jahres: Warum die Vengaboys nie wieder gehen dürfen
Mlb Hitting Streak Record Holder Crossword Clue
Random Warzone 2 Loadout Generator
Quest Diagnostics Mt Morris Appointment
Julies Freebies Instant Win
Fallout 76 Fox Locations
Goosetown Communications Guilford Ct
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 6568

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.