HowTo: Extract an RPM Package Files Without Installing It

by on October 18, 2006 · 42 comments· LAST UPDATED December 20, 2013

in , ,

As most of you may know to how extract a tarballs and/or a zip files. Someone, recently PM me with a question:

Dear nixCraft,

How do I extract an RPM package file without installing it on my Fedora Linux or CentOS or RHEL (Red Hat Enterprise Linux) Suse Linux?


CentOS user.

Extracting rpm file command

To be frank 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 rxtract 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:

pm2cpio myrpmfile.rpm
rpm2cpio - < myrpmfile.rpm
rpm2cpio myrpmfile.rpm | cpio -idmv

Examples - Extract files from rpm

Download an RPM file:
$ mkdir test
$ cd test
$ wget

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:

Fig.01: Browsing / viewing an rpm file with GNU Midnight Commander

Fig.01: Browsing / viewing an rpm file with GNU Midnight Commander

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:

Fig.02: The actual php rpm files are contained in the CONTENTS.cpio file

Fig.02: The actual php rpm files are contained in the CONTENTS.cpio file

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

Fig.03: Viewing php.conf file


I hope you will find these tips useful to extract configuration file or other file without installing an RPM file.

See also
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 42 comments… read them below or add one }

1 Ivan December 13, 2006 at 10:19 am

You can also use alien package to convert rpm to tgz…


2 nixCraft December 13, 2006 at 2:40 pm

Thanks for pointing out alien package to convert rpm to tgz.


3 Jared January 30, 2008 at 5:11 pm

thanks…worked first time


4 Jared January 30, 2008 at 5:12 pm

I love it when I search Google and find a good answer right away.

Thank you so much.


5 e! August 4, 2010 at 2:34 pm



6 Kulbir Saini May 25, 2008 at 3:06 pm

thanks a lot :)


7 Robert June 27, 2008 at 3:07 am

I just found this page and it is great. One thing to note is that opensuse compresses the cpio part with lzma to decrease size so you have to do something like the following instead.

rpm2cpio file.rpm | lzma -d | cpio -idmv

This will extract the files for you.


8 ram July 15, 2008 at 8:12 pm

Saved me a hole lot of time.

Thank you.


9 langda July 22, 2008 at 9:02 am

thanks a lot..


10 Matthew August 13, 2008 at 2:30 am

This is very good, however, I don’t think I see the installation script from inside the RPM. how do I get that? If I’m missing something, please let me know. Thank you!


11 nixCraft August 13, 2008 at 10:03 am


To display scripts you need to use rpm command as follows, this faq is about extracting file from rpm. In short type:
rpm -pq --scripts file.rpm
rpm -pq --scripts rsnapshot-1.3.0-1.noarch.rpm

Here is sample output from my rpm:

postinstall scriptlet (using /bin/sh):
# upgrade rsnapshot config file
RSNAPSHOT_CONFIG_VERSION=`/usr/bin/rsnapshot check-config-version`
if test $? != 0; then
        echo "Error upgrading /etc/rsnapshot.conf"
if test "$RSNAPSHOT_CONFIG_VERSION" = "1.2"; then
        # already latest version
        exit 0
if test "$RSNAPSHOT_CONFIG_VERSION" = "unknown"; then
        /usr/bin/rsnapshot upgrade-config-file
        exit $RETVAL



12 Samuel Benjamin August 22, 2008 at 12:29 pm

Excellent article that helped us save a lot of time from having to actually install a 64 bit linux system just to be able to retrieve the rpms for that platform.

I would suggest that the author remove the first two lines of the incomplete example which throws the user off until they realize that the cpio part has to be run together for actually extract the files.

No need to display :
rpm2cpio myrpmfile.rpm
rpm2cpio – < myrpmfile.rpm

(the above command dumps a continuous stream of unreadable characters to the screen)

Just need to know :
rpm2cpio myrpmfile.rpm | cpio -idmv

Thanks for sharing this with the linux community.

– Samuel Benjamin, NC.


13 Martijn September 24, 2008 at 10:04 am

Thanks, just what I needed.


14 Ritobroto Ram December 24, 2008 at 4:32 am

Just what I needed in the nick of time…

Thank You!!!


15 Sanjay January 31, 2009 at 1:42 am

Its really very fantastic search i ever made.


16 Marcio Carneiro February 27, 2009 at 10:33 pm

So, now I have the rpm opened and with all dirs.
Can I just mv to / and have program installed and running?
Yes, I know, if this works the rpm database is not updated.
But this works?


17 Anonymous May 19, 2010 at 11:09 am

Not with all packages; rpm executes [pre/post][install/uninstall] scripts contained in the rpm…


18 Balakumar March 23, 2009 at 6:23 am

Thanks Vivek,
It is very Useful


19 amit April 7, 2009 at 5:36 am

its very helpful :)


20 chetan May 16, 2009 at 4:21 pm

cool nice post


21 Zoid July 23, 2009 at 10:50 am

Hey, this worked great. I kept getting segmentation fault with plain old rpm and all I really needed from the rpm was some source files in a direction. :-)


22 Pete Wilson August 10, 2009 at 7:34 am

Fantastic! The command line as you gave it worked perfectly: 100% correct, unlike the usual almost-correct posting that I have to debug. You saved me hours of work. Thank you!


23 maghat April 30, 2010 at 3:52 pm

Thank you too. This post helped me a lot.


24 Jason July 23, 2010 at 12:38 am

I tried to extract a newer RPM (from Fedora 13 repository) on my Fedora 10 box and it wouldn’t work. The rpm2cpio program would not create a valid cpio file. I tried alien and it wouldn’t work either. I then did a “yum update rpm” and it downloaded the latest rpm package and that solved the problem.


25 soran February 2, 2011 at 2:13 pm

Thank,That is what I am looking for


26 John Braunhag February 22, 2011 at 6:26 pm

This is awesome, thank you so much!


27 jagan March 22, 2011 at 12:44 am

Excellent Post. Thank You very much.

I extracted my rpm using rpm2cpio myrpmfile.rpm | cpio -idmv .

Is ther a way to invoke some scripts from thei extracted folder.
Ex; I have a under scripts folder of above rpm. This need to be run automatically once we extarcted the rpm.


28 Blurry May 13, 2011 at 2:18 am

Sorry to dig up an old thread, but…

The free 7-zip does this too… It opens .rpm, you can see the .cpio, which it also opens, & you see the dir structure to browse.

Or just extract from the get go… Cant see the scripts though, which is what i came here looking for, so my thanks to you Vivek!



29 Blurry May 13, 2011 at 2:37 am

Now if i could edit said script…


30 liju June 8, 2011 at 4:06 am

install Pzip from “” and get it done easily.

The above command will not work as it showing “premature end of archive ” on Centos 5.6 32 bit architechure.


31 Scott August 19, 2011 at 11:54 pm

use an alternate of the above with the following
rpm2cpio | xz -d | cpio -idmv


32 toto September 19, 2011 at 7:20 am

good tutorial and very clear description and how to solve my problem. Thank for your tutorial. My problem about how to extract rpm file is solve :)


33 Marian Csontos November 25, 2011 at 9:06 am

The rpmpeek tool from rpmdevtools looks great:

       rpmpeek [-h] RPM command [args...]
       rpmpeek unpacks RPM contents into a temporary directory and executes a
       command under that directory.  The directory is purged upon exit.


34 Netra chhetri November 28, 2011 at 10:41 pm

Yap it works !!! i tried to convert prefix of the rpm so i unpack diffmerger rpm and repack using mavn-shell plugin and this rpm2cpio help me moving packages as i wanted !

Great Article :


35 rucov February 22, 2012 at 6:32 pm

I extracted an rpm file using this method and I tried other methods too. They all resulted in two directories (etc and usr). Now I was expecting to see a .spec file or something where the dependencies are listed but I can’t find it anywhere in the extraction path. I’m trying to learn where rpm -qpR gets it’s information from.

Any ideas?


36 Farooque Syed June 22, 2012 at 12:18 pm

Thank U Sir


37 Tricky July 5, 2012 at 7:10 pm

This put me on the right track. If you’re getting gibberish, the following might sort out your issue:

rpm2cpio myapp.rpm | bsdtar -xf -


38 Abdul January 24, 2013 at 10:48 am

Thanks. This is what i was looking for… :) very helpful


39 Andruss March 29, 2013 at 11:59 am

Midnight comander (mc) will open it for it and extract easialy.Just point to your rpm then cpio directory and here you go your files.


40 Erik January 11, 2014 at 10:19 am

In Ubuntu (works on 12.04) you can open the RPM using the compressed archive manager. I.e. right click and choose from the menu).


41 ben June 20, 2014 at 5:59 pm

big thumbs up for

rpm2cpio myrpmfile.rpm | cpio -idmv


That’s all I needed. Thanks!


42 Moataz Elmasry September 25, 2014 at 11:39 am

There’s a typo in the firsl rpm2cpio. It is written as pm2cpio


Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , ,

Previous post:

Next post: