Extract a file from a rpm package

Syntax is as follows:
rpm2cpio myrpmfile.rpm
rpm2cpio – < myrpmfile.rpm
rpm2cpio myrpmfile.rpm | cpio -idmv

Example

Download an RPM file:
$ mkdir test
$ cd test
$ wget http://nurfarhan.com/files/nurfarhan.rpm

Extract RPM file using rpm2cpio and cpio command:
$ rpm2cpio nurfarhan.rpm | cpio -idmvOutput:

/etc/httpd/conf.d/php.conf
./etc/php.d
./etc/php.ini
./usr/bin/php
./usr/bin/php-cgi
./usr/lib64/httpd/modules/libphp5.so
./usr/lib64/php
./usr/lib64/php/modules
....
.....
..
./var/lib/php/session
./var/www/icons/php.gif
19188 blocks

Output of rpm2cpio 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 current directory:
$ ls Output:

etc  nurfarhan.rpm  usr  var

This is useful if you want to extract configuration file or other file w/o installing an RPM file.

Leave a Reply