Extracting files from an RPM

In order to perform operations on a .rpm file, we use the rpm2cpio and cpio utilities. In order to list the files in an rpm:

rpm2cpio (rpm name) |cpio -itv

To extract an individual file from an rpm (into the current directory):
rpm2cpio (rpm name) |cpio -idv (filename)

And to extract all files from the rpm (once again, into the current directory):
rpm2cpio (rpm name) |cpio -idv

Here are some examples of "real-world" usage:

[root@www pam]# ls -l
total 24
-rw-r--r--    1 root     root        23392 Aug 18 06:40 pam_abl-0.2.2-2.fc3.i386.rpm
[root@www pam]# rpm2cpio pam_abl-0.2.2-2.fc3.i386.rpm |cpio -itv
-rw-r--r--   1 root     root          177 Jul 27  2005 ./etc/security/pam_abl.conf
-rwxr-xr-x   1 root     root        12944 Jul 27  2005 ./lib/security/pam_abl.so
-rwxr-xr-x   1 root     root        18024 Jul 27  2005 ./usr/sbin/pam_abl
drwxr-xr-x   4 root     root            0 Jul 27  2005 ./usr/share/doc/pam_abl-0.2.2
-rw-r--r--   1 root     root         2093 Jan  4  2005 ./usr/share/doc/pam_abl-0.2.2/Copyright
-rw-r--r--   1 root     root         1130 Jul 27  2005 ./usr/share/doc/pam_abl-0.2.2/README.Fedora
drwxr-xr-x   2 root     root            0 Jul 27  2005 ./usr/share/doc/pam_abl-0.2.2/conf
-rw-r--r--   1 root     root          177 Jan  4  2005 ./usr/share/doc/pam_abl-0.2.2/conf/pam_abl.conf
-rw-r--r--   1 root     root          681 Jul 27  2005 ./usr/share/doc/pam_abl-0.2.2/conf/system-auth
drwxr-xr-x   2 root     root            0 Jul 27  2005 ./usr/share/doc/pam_abl-0.2.2/doc
-rw-r--r--   1 root     root         2048 Jan  4  2005 ./usr/share/doc/pam_abl-0.2.2/doc/copying.html
-rw-r--r--   1 root     root        13950 Jan  4  2005 ./usr/share/doc/pam_abl-0.2.2/doc/index.html
-rw-r--r--   1 root     root         2991 Jan 10  2005 ./usr/share/doc/pam_abl-0.2.2/doc/pam_abl.html
-rw-r--r--   1 root     root          217 Jan  4  2005 ./usr/share/doc/pam_abl-0.2.2/doc/style.css
drwxr-xr-x   2 root     root            0 Jul 27  2005 ./var/lib/abl
111 blocks
[root@www pam]# rpm2cpio pam_abl-0.2.2-2.fc3.i386.rpm |cpio -idv ./etc/security/pam_abl.conf
./etc/security/pam_abl.conf
111 blocks
[root@www pam]# ls -l
total 28
drwx------    3 root     root         4096 Aug 18 06:43 etc
-rw-r--r--    1 root     root        23392 Aug 18 06:40 pam_abl-0.2.2-2.fc3.i386.rpm
[root@www pam]# cat ./etc/security/pam_abl.conf
# /etc/security/pam_abl.conf
# debug
host_db=/var/lib/abl/hosts.db
host_purge=2d
host_rule=*:10/1h,30/1d
user_db=/var/lib/abl/users.db
user_purge=2d
user_rule=!root:10/1h,30/1d
[root@www pam]# rpm2cpio pam_abl-0.2.2-2.fc3.i386.rpm |cpio -idv
cpio: ./etc/security/pam_abl.conf not created: newer or same age version exists
./etc/security/pam_abl.conf
./lib/security/pam_abl.so
./usr/sbin/pam_abl
./usr/share/doc/pam_abl-0.2.2
./usr/share/doc/pam_abl-0.2.2/Copyright
./usr/share/doc/pam_abl-0.2.2/README.Fedora
./usr/share/doc/pam_abl-0.2.2/conf
./usr/share/doc/pam_abl-0.2.2/conf/pam_abl.conf
./usr/share/doc/pam_abl-0.2.2/conf/system-auth
./usr/share/doc/pam_abl-0.2.2/doc
./usr/share/doc/pam_abl-0.2.2/doc/copying.html
./usr/share/doc/pam_abl-0.2.2/doc/index.html
./usr/share/doc/pam_abl-0.2.2/doc/pam_abl.html
./usr/share/doc/pam_abl-0.2.2/doc/style.css
./var/lib/abl
111 blocks
[root@www pam]# ls -lR
.:
total 40
drwx------    3 root     root         4096 Aug 18 06:43 etc
drwx------    3 root     root         4096 Aug 18 06:44 lib
-rw-r--r--    1 root     root        23392 Aug 18 06:40 pam_abl-0.2.2-2.fc3.i386.rpm
drwx------    4 root     root         4096 Aug 18 06:44 usr
drwx------    3 root     root         4096 Aug 18 06:44 var
./etc:
total 4
drwx------    2 root     root         4096 Aug 18 06:43 security
./etc/security:
total 4
-rw-r--r--    1 root     root          177 Aug 18 06:43 pam_abl.conf
./lib:
total 4
drwx------    2 root     root         4096 Aug 18 06:44 security
./lib/security:
total 16
-rwxr-xr-x    1 root     root        12944 Aug 18 06:44 pam_abl.so
./usr:
total 8
drwx------    2 root     root         4096 Aug 18 06:44 sbin
drwx------    3 root     root         4096 Aug 18 06:44 share
./usr/sbin:
total 20
-rwxr-xr-x    1 root     root        18024 Aug 18 06:44 pam_abl
./usr/share:
total 4
drwx------    3 root     root         4096 Aug 18 06:44 doc
./usr/share/doc:
total 4
drwxr-xr-x    4 root     root         4096 Aug 18 06:44 pam_abl-0.2.2
./usr/share/doc/pam_abl-0.2.2:
total 16
drwxr-xr-x    2 root     root         4096 Aug 18 06:44 conf
-rw-r--r--    1 root     root         2093 Aug 18 06:44 Copyright
drwxr-xr-x    2 root     root         4096 Aug 18 06:44 doc
-rw-r--r--    1 root     root         1130 Aug 18 06:44 README.Fedora
./usr/share/doc/pam_abl-0.2.2/conf:
total 8
-rw-r--r--    1 root     root          177 Aug 18 06:44 pam_abl.conf
-rw-r--r--    1 root     root          681 Aug 18 06:44 system-auth
./usr/share/doc/pam_abl-0.2.2/doc:
total 28
-rw-r--r--    1 root     root         2048 Aug 18 06:44 copying.html
-rw-r--r--    1 root     root        13950 Aug 18 06:44 index.html
-rw-r--r--    1 root     root         2991 Aug 18 06:44 pam_abl.html
-rw-r--r--    1 root     root          217 Aug 18 06:44 style.css
./var:
total 4
drwx------    3 root     root         4096 Aug 18 06:44 lib
./var/lib:
total 4
drwxr-xr-x    2 root     root         4096 Aug 18 06:44 abl
./var/lib/abl:
total 0

And there you have it!

Submitted by jkelly on Fri, 2006-08-18 06:48. categories [ | | ] login or register to post comments