Ever came across situation wherein you need to extract file from rpm?
This post may help you to extract single file from rpm. No need to install rpm again to retrieve single file.
e.g by mistake I deleted /bin/ls
now I can not work without ls as I have habit to run ls after I change folder. so how do I recover /bin/ls ?
I need to have rpm2cpio, this is bundled with rpm-x.x.x…i386.rpm.
now I need to findout which rpm contains /bin/ls
yum whatprovides /bin/ls
coreutils-5.97-19.el5.i386.rpm contains /bin/ls in CentOS-5.3
now if i try to install using yum,
Package coreutils-5.97-19.el5.i386 already installed and latest version
To restore /bin/ls all I need is coreutils-5.97-19.el5.i386.rpm
rpm2cpio coreutils-5.97-19.el5.i386.rpm | cpio -idmv
cp bin/ls /bin/
this is all you need to restore specific command / file from rpm.
yes there is another way by forcefully installing rpm
rpm -ivh coreutils-5.97-19.el5.i386.rpm –force
this was just an example for ls, in case if you loose ls due to some hardware error / human error, you can keep work going by command dir.
if you find any missing point in here, please let us know in comment section or tweet us at @linuxreaders. To get more articles like this, subscribe to our RSS feeds / Mails.