Extract an RPM Package content without installation

To totally unlock this section you need to Log-in

To be clear, there is no direct option available for rpm command to extract an RPM file. But there is a small nifty utility available called rpm2cpio. It extract cpio archive from RPM Package Manager (RPM) package. With the following hack you will be able to extract an RPM file.

First you use rpm2cpio to convert the .rpm file into a cpio archive on standard out. If a - argument is given, an rpm stream is read from standard in. The basic syntax is as follows:

rpm2cpio myrpmfile.rpm
rpm2cpio - < myrpmfile.rpm
rpm2cpio myrpmfile.rpm | cpio -idmv
Examples – Extract files from rpm

Download an RPM file:

$ mkdir test
$ cd test
$ wget http://www.example.com/files/php-5.1.4-1.esp1.x86_64.rpm

To extract RPM file using rpm2cpio and cpio command, type:

$ rpm2cpio php-5.1.4-1.esp1.x86_64.rpm | cpio -idmv

Sample outputs:

19188 blocks

In this example, output of rpm2cpio command piped to cpio command with following options:

i: Restore archive
d: Create leading directories where needed
m: Retain previous file modification times when creating files
v: Verbose i.e. display progress

Verify that you have extracted an RPM file in the current directory:

$ ls

Sample outputs:

etc  php-5.1.4-1.esp1.x86_64.rpm  usr  var

Say hello to Midnight Commander

GNU Midnight Commander (mc) is a directory browser/file manager for Unix-like operating systems. Install mc using the following yum command:

# yum install mc

Opening an RPM file using Midnight Commander (mc)

You can use mc command as follows to browse or extract rpm files:

# mc

Sample outputs:

Extract an RPM Package content without installation

Next select an RPM file (such as php-5.3*.rpm) by highlighting the package name and press Enter key. You need to select CONTENTS.cpio file:

Extract an RPM Package content without installation

To view/edit/extract files click or press on the special function keys. In this example, we pressed F3 function key to view php.conf file:

Extract an RPM Package content without installation