抽取rpm源码包

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 http://www.cyberciti.biz/files/lighttpd/rhel4-php5-fastcgi/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:

/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
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 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

Conclusion

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

Ref:  http://www.cyberciti.biz/tips/how-to-extract-an-rpm-package-without-installing-it.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值