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
Travel insurance for Australians
Best 2024 Training Needs Analysis Templates, TNA Toolkit & Dashboards – OCM Solution
Dreams Of Milk Anr
Wednesday Morning Gifs
Skip The Games Huntsville Al
Contact Spectrum Customer Service
Ky Smartgov
Q58 Bus Schedule
Anastasiya Kvitko Forum
7 Categories Of Hazardous Waste For Dollar General
Jtv Jackson
Vidant My Chart Login
Standard Page Field
Lvh Remote Access
Les 3 meilleurs bivy-bags pour le bikepacking en 2023
Cómo lograr un color borgoña en el cabello negro
417-990-0201
Wisconsin Volleyball Coco Star
Closest Dollar Tree Store To My Location
Celebrity Gues Tape
Lake Ridge Ixl
24 Hour Drive Thru Car Wash Near Me
Used Troy Bilt Tiller For Sale Craigslist
Remote Icloud Quota Ui
Dashmart Bloomington
Is Chanel West Coast Pregnant Due Date
Express Employment Sign In
Rhiel Funeral Durand
Dollar General Warehouse Pay Rate
George The Animal Steele Gif
Uncovering The Mystery Behind Crazyjamjam Fanfix Leaked
Farosh's Horn Botw
Ritz Carlton San Antonio Riverwalk
Where To Cook In Gerudo Town
Is Buffalo Bills Singletary Related To Mike Singletary
Www Craigslist Denver Com
Uncle Jemima's Mash Whiskey Snl Youtube
Kornerstone Funeral Tulia
Albertville Memorial Funeral Home Obituaries
2021 Silverado 1500 Lug Nut Torque
Look Who Got Busted Gregg County
HarifSport - Bet Ethiopia
American Iris Society Wiki
Service Flat / Unsinn ?
Theobromine: Benefits and Side Effects of Cocoa’s Interesting Phytochemical
Fantasy Football Trade Advice: Players to Buy & Sell (Week 3)
Syracuse Pets Craigslist
Ixl Jobcorps
Studio apartments for rent in Marseille, France - Rentberry
Mail From Po Box 1111 Charlotte Nc 28201
Parc Soleil Drowning
Funbox Lone Tree Tickets
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.