cpio/rpm2cpio commands : How to extract an RPM package without installing it?

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

How do I extract an RPM package without installing it on my rhel5?

To be frank there is no direct RPM option available via 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.

So rpm2cpio converts the .rpm file specified as a single argument to a cpio archive on standard out. If a - argument is given, an rpm stream is read from standard in.

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://www.cyberciti.biz/files/lighttpd/rhel4-php5-fastcgi/php-5.1.4-1.esp1.x86_64.rpm

Extract RPM file using rpm2cpio and cpio command:

$ rpm2cpio php-5.1.4-1.esp1.x86_64.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 (see how to use cpio) 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 php-5.1.4-1.esp1.x86_64.rpm usr var

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

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates.

Related Linux / UNIX Tips:

* Download of the day: e tool to extract rpm, rar, zip and other formats under Linux

* How to extract files from ISO CD images in Linux

* RHEL / CentOS Support 4GB or more RAM ( memory )

* FreeBSD changing pkg_add package ftp site location

* Uninstall files installed from a source code tar-ball

------------------------------------------------------------------------------------------

cpio/rpm2cpio commands

To extract a cpio file:

$ cpio -iv &lt; cpio_file

To list the contents of a cpio file:

$ cpio -itv &lt; cpio_file

To create a cpio file with all files in the current directory:

$ ls | cpio -o > cpio_file

To extract all files from an RPM:

$ rpm2cpio RPM_file | cpio -idv

To extract individual file(s) from an RPM:

$ rpm2cpio RPM_file | cpio -id individual_file(s)

e.g. Extracting libcrypto.so.0.9.7a and libssl.so.0.9.7a from openssl-0.9.7a-2.i386.rpm:

$ rpm2cpio openssl-0.9.7a-2.i386.rpm | cpio -it egrep "libcrypto.so.0.9.7a|libssl.so.0.9.7a"

-rwxr-xr-x 1 root root 992092 Feb 27 12:10 ./lib/libcrypto.so.0.9.7a

-rwxr-xr-x 1 root root 216004 Feb 27 12:10 ./lib/libssl.so.0.9.7a

$ rpm2cpio openssl-0.9.7a-2.i386.rpm | cpio -idv ./lib/libssl.so.0.9.7a ./lib/libcrypto.so.0.9.7a

This will extract the two files from the RPM into a ./lib subdirectory.

To extract individual files from a Sun Flash Archive file:

1. Split the Flash Archive into the cookie, identification, and archive files.

$ flar split Flash_Archive_file

2. Extract the file(s) from the cpio archive.

e.g. extracting var/sadm/install/contents

$ cpio -idv var/sadm/install/contents < archive

Back to brandonhutchinson.com.

Using rpm2cpio

From time to time, you might find it necessary to extract one or more files from a package file. One way to do this would be to:

* Install the package

* Make a copy of the file(s) you need

* Erase the package

An easier way would be to use rpm2cpio.

rpm2cpio -- What does it do?

As the name implies, rpm2cpio takes an RPM package file and converts it to a cpio archive. Because it's written to be used primarily as a filter, there's not much to be specified. rpm2cpio takes only only one argument, and even that's optional!

The optional argument is the name of the package file to be converted. If there is no filename specified on the command line, rpm2cpio will simply read from standard input and convert that to a cpio archive. Let's give it a try:

# rpm2cpio logrotate-1.0-1.i386.rpm

0707020001a86a000081a4000000000000000000000001313118bb000002c200000008000

000030000000000000000000000190000e73eusr/man/man8/logrotate.8." logrotate

- log fi

le rotator

.TH rpm 8 "28 November 1995" "Red Hat Software" "Red Hat Linux"

.SH NAME

(We've just shown the first few lines of output.)

What on earth is all that stuff? Remember, rpm2cpio is written as a filter. It writes the cpio archive contained in the package file to standard output, which, if you've not redirected it somehow, is your screen. Here's a more reasonable example:

# rpm2cpio logrotate-1.0-1.i386.rpm > blah.cpio

# file blah.cpio

blah.cpio: ASCII cpio archive (SVR4 with CRC)

#

Here we've directed rpm2cpio to convert the logrotate package file. We've also redirected rpm2cpio's output to a file called blah.cpio. Next, using the file command, we find that the resulting file is indeed a true-blue cpio archive file. The following command is entirely equivalent to the one above and shows rpm2cpio's ability to read the package file from its standard input:

# cat logrotate-1.0-1.i386.rpm | rpm2cpio &gt; blah.cpio

#

A more real-world example -- Listing the files in a package file

While there's nothing wrong with using rpm2cpio to actually create a cpio archive file, it's takes a few more steps and uses a bit more disk space than is strictly necessary. A somewhat cleaner approach would be to pipe rpm2cpio's output directly into cpio:

# rpm2cpio logrotate-1.0-1.i386.rpm | cpio -t

usr/man/man8/logrotate.8

usr/sbin/logrotate

14 blocks

#

In this example, we used the -t option to direct cpio to produce a ``table of contents'' of the archive created by rpm2cpio. This can make it much easier to get the right filename and path when you want to extract a file.

Extracting one or more files from a package file

Continuing the example above, let's extract the man page from the logrotate package. In the table of contents, we see that the full path is usr/man/man8/logrotate.8. All we need to do is to use the filename and path as shown below:

# rpm2cpio logrotate-1.0-1.i386.rpm |cpio -ivd usr/man/man8/logrotate.8

usr/man/man8/logrotate.8

14 blocks

#

In this case, the cpio options -i, -v, and -d direct cpio to:

* Extract one or more files from an archive.

* Display the names of any files processed, along with the size of the archive file, in 512-byte blocks.1

* Create any directories that precede the filename specified in the cpio command.

So where did the file end up? The last option (-d) to cpio provides a hint. Let's take a look:

# ls -al

total 5

-rw-rw-r-- 1 root root 3918 May 30 11:02 logrotate-1.0-1.i386.rpm

drwx------ 3 root root 1024 Jul 14 12:42 usr

# cd usr

# ls -al

total 1

drwx------ 3 root root 1024 Jul 14 12:42 man

# cd man

# ls -al

total 1

drwx------ 2 root root 1024 Jul 14 12:42 man8

# cd man8

# ls -al

total 1

-rw-r--r-- 1 root root 706 Jul 14 12:42 logrotate.8

# cat logrotate.8

.\" logrotate - log file rotator

.TH rpm 8 "28 November 1995" "Red Hat Software" "Red Hat Linux"

.SH NAME

logrotate \- log file rotator

.SH SYNOPSIS

\fBlogrotate\fP [configfiles]

.SH DESCRIPTION

\fBlogrotate\fP is a tool to prevent log files from growing without

Since the current directory didn't have a usr/man/man8/ path in it, the -d option caused cpio to create all the directories leading up to the logrotate.8 file in the current directory. Based on this, it's probably safest to use cpio outside the normal system directories unless you're comfortable with cpio, and you know what you're doing!

cpio/rpm2cpio 命令相关推荐

  1. cpio备份linux系统,linux cpio 备份命令

    cpio 命令[root@linux ~]# cpio -covB > [file|device] <==备份 [root@linux ~]# cpio -icduv < [file ...

  2. linux 提取cpio_【rpm】从rpm包中提取文件:rpm2cpio和cpio的使用

    rpm2cpio命令可以用于将rpm格式的文件转为cpio格式的文件. rpm是Linux中常用的文件格式,方便了用户的安装,但没有cpio格式灵活. cpio是用来建立,还原备份档的工具程序,它可以 ...

  3. oracle cpio,cpio - 手册页部分 1: 用户命令

    cpio(1) 名称cpio - 将文件复制进/复制出归档 用法概要 cpio -i [-bBcdfkmPrsStuvV6@/] [-C bufsize] [-E file] [-H header] ...

  4. Linux 命令之 yum -- 基于 RPM 的软件包管理器

    文章目录 一.命令介绍 二.选项参数 选项 参数 三.配置文件 四.参考示例 (一)安装.升级和删除包 安装指定的软件包 强制重新安装 本地安装指定软件包 本地更新指定软件包 安装 yum 服务器中的 ...

  5. linux coreutils升级,Linux命令01--Coreutils软件包01--认识coreutils

    //通过ls命令的所属软件包来获取coreutils软件包的版本 #rpm -qf /bin/ls >>>coreutils-8.22-18.el7.x86_64 //下载yumdo ...

  6. linux之rpm命令

    RPM 软件包的管理工具 rpm 命令 是 RPM 软件包的管理工具.rpm 原本是 Red Hat Linux 发行版专门用来管理 Linux 各项套件的程序,由于它遵循 GPL 规则且功能强大方便 ...

  7. Linux命令之rpm命令

            rpm命令 是RPM软件包的管理工具.rpm原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序,由于它遵循GPL规则且功能强大方便,因而广受欢迎.逐渐受到其他发 ...

  8. Linux rpm命令用法

    rpm命令是RPM软件包的管理工具.rpm原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序,由于它遵循GPL规则且功能强大方便,因而广受欢迎.逐渐受到其他发行版的采用.RPM ...

  9. rpm命令手册和查看rpm安装包的安装路径的方法

    rpm -qpl xxxxxx.rpm 1.如何安装rpm软件包 rmp软件包的安装可以使用程序rpm来完成.执行下面的命令 rpm -i your-package.rpm 其中your-packag ...

最新文章

  1. java进销存培训_Java实例学习——企业进销存管理系统(2)
  2. windows 下anaconda创建环境慢的解决办法
  3. html:(20):使用下拉框进行多选和使用提交按钮提交
  4. 关于Linux开源项目基础组件make编译流程
  5. 循环计数_FOR 循环
  6. 面试官问你如何解决web高并发这样回答就好了
  7. Android开发笔记(一百二十七)活用提示窗Toast和Snackbar
  8. in-list iterator
  9. 今日头条成锤子“接盘侠”?“是真的!”
  10. 浅谈OWASP TOP 10
  11. 软件性能分析与优化详解
  12. windbg 常用调试命令总结
  13. 如何使用LaTeX完成一篇论文的基本排版
  14. 最新高品质+武汉城区建筑物范围面shp格式+小区大厦学校医院占地面积
  15. CSS3各种手型样式集合
  16. 快乐想象识字认字注册码发放!
  17. 平面桁架静力计算程序
  18. 用AI变革新药研发,终极目标是延缓衰老,这家创业公司迎来“里程碑”
  19. c语言程序设计勘误,《程序设计基础教程(C语言)》勘误表
  20. 怎么查看linux服务器品牌,怎么查看Linux服务器硬件信息,这些命令告诉你

热门文章

  1. 客户端负载均衡Ribbon之一:Spring Cloud Netflix负载均衡组件Ribbon介绍
  2. Mysql 表字段(列)编辑 (增删改)
  3. J2EE从servlet开始
  4. 肏蛋的Loadrunner脚本
  5. 10 个有用的 PHP 代码
  6. 改进C#代码之24:通过定义并实现接口替代继承
  7. 红帽子RedHat Linux 9.0安装图解(图)
  8. ASP.NET JScript公共类(非常有用)
  9. mysql物理文件组成
  10. 浅淡Windows7 32位与64位/x86与x64的区别