Question : How can I extract single and selected files from RPM package on Linux.
Answer : You can extract the single and number of selected files from RPM package by using rpm2cpio and cpio command.To achieve this task we will first list the number of files inside RPM package. After getting files name, we will selectively extract these files.
listing the files from RPM package by using given below command
Syntax:
rpm2cpio package-name.rpm |cpio -t
Extract single file from RPM package
Syntax:
rpm2cpio package-name.rpm |cpio -ivdm filename1
Extract multiple selected files from RPM package
Syntax:
rpm2cpio package-name.rpm |cpio -ivdm filename1 filename2 filename3 filename-N
Understand more ,with below given example
[root@localhost ~]# mkdir extract [root@localhost ~]# cp -p epel-release-6-8.noarch.rpm extract/ [root@localhost ~]# cd extract/ [root@localhost extract]# ls epel-release-6-8.noarch.rpm [root@localhost extract]# [root@localhost extract]# [root@localhost extract]# rpm2cpio epel-release-6-8.noarch.rpm |cpio -t ./etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 ./etc/rpm/macros.ghc-srpm ./etc/yum.repos.d/epel-testing.repo ./etc/yum.repos.d/epel.repo ./usr/share/doc/epel-release-6 ./usr/share/doc/epel-release-6/GPL 46 blocks [root@localhost extract]# [root@localhost extract]# [root@localhost extract]# rpm2cpio epel-release-6-8.noarch.rpm |cpio -ivdm ./etc/rpm/macros.ghc-srpm ./etc/rpm/macros.ghc-srpm 46 blocks [root@localhost extract]# [root@localhost extract]# ls -l total 20 -rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm drwxr-xr-x. 3 root root 4096 Mar 26 17:48 etc [root@localhost extract]# ls etc/rpm/macros.ghc-srpm etc/rpm/macros.ghc-srpm [root@localhost extract]# rm -fr e epel-release-6-8.noarch.rpm etc/ [root@localhost extract]# rm -fr etc/ [root@localhost extract]# [root@localhost extract]# rpm2cpio epel-release-6-8.noarch.rpm |cpio -t ./etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 ./etc/rpm/macros.ghc-srpm ./etc/yum.repos.d/epel-testing.repo ./etc/yum.repos.d/epel.repo ./usr/share/doc/epel-release-6 ./usr/share/doc/epel-release-6/GPL 46 blocks [root@localhost extract]# rpm2cpio epel-release-6-8.noarch.rpm |cpio -ivdm ./etc/yum.repos.d/epel.repo ./usr/share/doc/epel-release-6 ./etc/yum.repos.d/epel.repo ./usr/share/doc/epel-release-6 46 blocks [root@localhost extract]# ls -l total 24 -rw-r--r--. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm drwxr-xr-x. 3 root root 4096 Mar 26 17:49 etc drwxr-xr-x. 3 root root 4096 Mar 26 17:49 usr [root@localhost extract]# ls etc/yum.repos.d/epel.repo etc/yum.repos.d/epel.repo [root@localhost extract]# ls usr/share/doc/epel-release-6/ [root@localhost extract]# ls -ld usr/share/doc/epel-release-6/ drwxr-xr-x. 2 root root 4096 Nov 5 2012 usr/share/doc/epel-release-6/ [root@localhost extract]# [root@localhost extract]#