How To: Extract an RPM Package Files Without Installing It

You may know to how to extract a tarball and zip files on Linux and Unix-like system. 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 using combination of rpm2cpio and cpio command

To be frank, there is no direct option available for the rpm command to extract an RPM file. However, there is a small nifty utility available called rpm2cpio. It extracts cpio archive from RPM Package Manager (RPM) package. With the following hack, you will be able to extract an RPM file. First you use the 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

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 the rpm2cpio command piped to the cpio command with the 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 tar command

Another option is just use the tar command:
$ tar xvf file.rpm

Related: How to extract a .deb file without opening it on Debian or Ubuntu Linux

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

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

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

Say hello to tar command

Another option is just use the BSD tar command:
$ tar xvf file.rpm
Please note that this option only works with the BSD version of tar command. So if you are on MacOS or FreeBSD try the tar command to extract an rpm file.


I hope you found these tips useful to extract configuration file or another file without installing an RPM file.

See also

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 43 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
43 comments… add one
  • Ivan Dec 13, 2006 @ 10:19

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

  • 🐧 nixCraft Dec 13, 2006 @ 14:40

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

  • Jared Jan 30, 2008 @ 17:11

    thanks…worked first time

  • Jared Jan 30, 2008 @ 17:12

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

    Thank you so much.

    • e! Aug 4, 2010 @ 14:34

      *THUMBS UP* 🙂

  • Kulbir Saini May 25, 2008 @ 15:06

    thanks a lot 🙂

  • Robert Jun 27, 2008 @ 3:07

    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.

  • ram Jul 15, 2008 @ 20:12

    Saved me a hole lot of time.

    Thank you.

  • langda Jul 22, 2008 @ 9:02

    thanks a lot..

  • Matthew Aug 13, 2008 @ 2:30

    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!

  • 🐧 nixCraft Aug 13, 2008 @ 10:03


    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:



  • Samuel Benjamin Aug 22, 2008 @ 12:29

    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.

  • Martijn Sep 24, 2008 @ 10:04

    Thanks, just what I needed.

  • Ritobroto Ram Dec 24, 2008 @ 4:32

    Just what I needed in the nick of time…

    Thank You!!!

  • Sanjay Jan 31, 2009 @ 1:42

    Its really very fantastic search i ever made.

  • Marcio Carneiro Feb 27, 2009 @ 22:33

    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?

    • Anonymous May 19, 2010 @ 11:09

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

  • Balakumar Mar 23, 2009 @ 6:23

    Thanks Vivek,
    It is very Useful

  • amit Apr 7, 2009 @ 5:36

    its very helpful 🙂

  • chetan May 16, 2009 @ 16:21

    cool nice post

  • Zoid Jul 23, 2009 @ 10:50

    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. 🙂

  • Pete Wilson Aug 10, 2009 @ 7:34

    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!

    • maghat Apr 30, 2010 @ 15:52

      Thank you too. This post helped me a lot.

  • Jason Jul 23, 2010 @ 0:38

    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.

  • soran Feb 2, 2011 @ 14:13

    Thank,That is what I am looking for

  • John Braunhag Feb 22, 2011 @ 18:26

    This is awesome, thank you so much!

  • jagan Mar 22, 2011 @ 0:44

    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.

  • Blurry May 13, 2011 @ 2:18

    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!


  • Blurry May 13, 2011 @ 2:37

    Now if i could edit said script…

  • liju Jun 8, 2011 @ 4:06

    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.

  • Scott Aug 19, 2011 @ 23:54

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

  • toto Sep 19, 2011 @ 7:20

    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 🙂

  • Marian Csontos Nov 25, 2011 @ 9:06

    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.
  • Netra chhetri Nov 28, 2011 @ 22:41

    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 :

  • rucov Feb 22, 2012 @ 18:32

    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?

  • Farooque Syed Jun 22, 2012 @ 12:18

    Thank U Sir

  • Tricky Jul 5, 2012 @ 19:10

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

    rpm2cpio myapp.rpm | bsdtar -xf -
  • Abdul Jan 24, 2013 @ 10:48

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

  • Andruss Mar 29, 2013 @ 11:59

    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.

  • Erik Jan 11, 2014 @ 10:19

    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).

  • ben Jun 20, 2014 @ 17:59

    big thumbs up for

    rpm2cpio myrpmfile.rpm | cpio -idmv


    That’s all I needed. Thanks!

  • Moataz Elmasry Sep 25, 2014 @ 11:39

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

  • Mark Oct 13, 2015 @ 19:56

    Saved my life there!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum