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
2022 Beginner's Guide to Credit Card Chargebacks - Shopify
Hanley Investment Group Arranges Sale of New-Construction Single-Tenant Raising Cane’s in St. Louis to Southern California Buyer for $5.03 Million
Ron Martin Realty Cam
Cars & Trucks - By Owner near Kissimmee, FL - craigslist
Jeremy Corbell Twitter
Wausau Marketplace
Dr Doe's Chemistry Quiz Answer Key
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Shariraye Update
1Win - инновационное онлайн-казино и букмекерская контора
How to Store Boiled Sweets
[Birthday Column] Celebrating Sarada's Birthday on 3/31! Looking Back on the Successor to the Uchiha Legacy Who Dreams of Becoming Hokage! | NARUTO OFFICIAL SITE (NARUTO & BORUTO)
Payment and Ticket Options | Greyhound
Elemental Showtimes Near Cinemark Flint West 14
Team C Lakewood
Is Windbound Multiplayer
Who is Jenny Popach? Everything to Know About The Girl Who Allegedly Broke Into the Hype House With Her Mom
A Man Called Otto Showtimes Near Cinemark University Mall
Airtable Concatenate
Https E22 Ultipro Com Login Aspx
Suspiciouswetspot
Superhot Free Online Game Unblocked
Guinness World Record For Longest Imessage
DIY Building Plans for a Picnic Table
Hotel Denizen Mckinney
Gwen Stacy Rule 4
Composite Function Calculator + Online Solver With Free Steps
Exploring The Whimsical World Of JellybeansBrains Only
Missouri State Highway Patrol Will Utilize Acadis to Improve Curriculum and Testing Management
CVS Near Me | Somersworth, NH
Games R Us Dallas
Wsbtv Fish And Game Report
Midsouthshooters Supply
Wal-Mart 2516 Directory
18006548818
Tableaux, mobilier et objets d'art
2Nd Corinthians 5 Nlt
Why Are The French So Google Feud Answers
Dontrell Nelson - 2016 - Football - University of Memphis Athletics
Interminable Rooms
Greatpeople.me Login Schedule
Ratchet And Clank Tools Of Destruction Rpcs3 Freeze
Windy Bee Favor
The top 10 takeaways from the Harris-Trump presidential debate
What Does the Death Card Mean in Tarot?
Amourdelavie
Prologistix Ein Number
Taterz Salad
Duffield Regional Jail Mugshots 2023
Texas 4A Baseball
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.