• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Extract single and selected files from RPM package on Linux

March 26, 2014 by Sharad Chhetri Leave a Comment

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]#

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to extract RPM package on Linux system
  2. linux command to list the files from rpm package without extracting
  3. Read the file inside compressed .gz files without extract
  4. rsync all files,hidden files,symlinks,hardlinks to remotes Linux Server
  5. How to find installation date and time of rpm package
  6. How to test rpm package before installation
  7. How to create OpenSSH rpm package and its upgrade
  8. yum : how to find rpm package which has certain command or file
  9. Yum command to download rpm file without installing in linux system
  10. How to rename and move the directory and files in linux

Filed Under: Linux Tagged With: rpm

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

Allow wget and yum in iptable

How to empty Trash through command line in Ubuntu

How to hide php version information in header

Agent admitted failure to sign using the key ssh

Allow only members of Wheel group to use su command on RHEL/CentOS

How to forcefully send mail from mailq in sendmail MTA

How to protect from port scanning and smurf attack in Linux Server by iptables

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy