LLI Wiki — My Digital Knowledge Base

Extract a single file from an RPM package

Download an RPM package and extract one file from it without installing the package, using rpm2cpio and cpio.

This guide explains how to extract a single file from an RPM package without installing the package, using rpm2cpio and cpio.

Download the package

The Red Hat package browser lets you browse and download RPM packages.

On a system that uses yum, the package can also be located from the command line. yumdownloader is provided by the yum-utils package:

yumdownloader --destdir=/home/user/ openscap-utils
repoquery --location openscap-utils

repoquery --location prints the package URL, which can then be fetched with wget or curl.

List the package contents

rpm2cpio package-name.rpm | cpio -t

Extract one file

Example with the package epel-release-6-8.noarch.rpm:

mkdir extract
cd extract/
rpm2cpio epel-release-6-8.noarch.rpm | cpio -ivdm ./etc/yum.repos.d/epel.repo
./etc/yum.repos.d/epel.repo
46 blocks

The file is extracted into the current directory, keeping its relative path (here etc/yum.repos.d/epel.repo).

cpio options used

Option Effect
-i Extract (copy-in)
-v Print the names of the files processed
-d Create the leading directories where needed
-m Preserve the modification time
-t List the archive contents (no extraction)
Mastodon LLIMastodon SocialFosstodon