SysTutorials

Extract Files from a .deb Package Without Installing

· updated April 12, 2026

[md] When you need to inspect what files a .deb package contains or will install, dpkg is your primary tool. This is useful for understanding package contents before installation, checking what files a package added to your system, or troubleshooting file conflicts.

## Listing Files in an Installed Package

If the package is already installed on your system:

dpkg -L package-name

This lists all files the package owns, including configuration files, binaries, libraries, and documentation. For example:

dpkg -L curl | head -20

## Listing Files in a .deb File (Not Installed)

To inspect a .deb file before installing it:

dpkg-deb -c package.deb

This shows the file listing with permissions, ownership, and size — similar to tar -tvf output. The format shows:

– File permissions (drwxr-xr-x for directories, -rw-r–r– for files) – Owner and group – File size – Full installation path

To see just the file names without metadata:

dpkg-deb -c package.deb | awk '{print $NF}'

## Using apt-file for Remote Packages

If you don’t have the .deb file downloaded and the package isn’t installed:

sudo apt install apt-file
sudo apt-file update
apt-file list package-name

This queries the package repository database to show what files the package would install. It works for any package in your configured repositories, even if you haven’t installed it.

## Using ar and tar for Manual Extraction

A .deb file is actually an ar archive. You can manually extract and inspect it:

# Extract the .deb archive
ar x package.deb

# This creates three files:
# debian-binary  - format version
# control.tar.*  - package metadata and install scripts
# data.tar.*     - actual files to be installed

# List files in the data archive
tar -tzf data.tar.gz     # gzip compressed
tar -tJf data.tar.xz     # xz compressed
tar -tjf data.tar.bz2    # bzip2 compressed

To extract just the data files to a temporary directory for inspection:

mkdir /tmp/pkg-inspect
tar -xzf data.tar.gz -C /tmp/pkg-inspect
find /tmp/pkg-inspect -type f

## Inspecting Package Metadata

The control archive contains useful metadata:

# Extract control information
ar x package.deb
tar -xzf control.tar.gz ./control

# View package metadata
cat control

This shows the package name, version, dependencies, maintainer, description, and other metadata that dpkg uses.

## Find Which Package Owns a File

If you have a file on your system and want to know which package installed it:

dpkg -S /path/to/file

Examples:

dpkg -S /usr/bin/curl        # curl: /usr/bin/curl
dpkg -S /etc/nginx/nginx.conf  # nginx-common: /etc/nginx/nginx.conf

You can also search by filename pattern:

dpkg -S '*/bin/curl'

## Common Use Cases

**Check what a package will install before installing:**

apt-file list nginx

**Verify all files from an installed package are intact:**

dpkg -V package-name

This checks file checksums against the package database and reports any modifications.

**List only configuration files:**

dpkg -L package-name | grep /etc/

**List only executables:**

dpkg -L package-name | grep bin/

## One-Command Summary

Quick reference for the most common operations:

– dpkg -L pkg — list files from installed package – dpkg-deb -c file.deb — list files in .deb archive – dpkg -S /path — find which package owns a file – dpkg -V pkg — verify installed files – apt-file list pkg — list files from remote package

← All posts