How to extract a file from an rpm to the current directory?

PabloDario picture PabloDario · May 16, 2013 · Viewed 13.9k times · Source

I recently found out about the existence of cpio and how it can be used, among many other things, to extract individual files from an rpm in conjunction with the rpm2cpio tool, like this:

rpm2cpio mypackage.rpm | cpio -idmv ./path/to/individual/file/inside/the/rpm/filename.txt

The problem is that this command will create the directory that matches the file's location inside the rpm, i.e., it will create the directory /path/to/individual/file/inside/the/rpm/ inside the current directory before actually extracting the file.

Is there any way to extract the file to the current directory without creating the whole directory structure?

Thanks in advance!!

Answer

Aaron D. Marasco picture Aaron D. Marasco · May 17, 2013

You can use --to-stdout for cpio. E.g.:

# rpm2cpio id3lib-3.8.3-28.fc18.x86_64.rpm | cpio -iv --to-stdout ./usr/share/doc/id3lib-3.8.3/README > /tmp/README
./usr/share/doc/id3lib-3.8.3/README
2173 blocks
#