How-To extract the content of a RPM

It is sometime handy to handy to be able to extract a RPM without installing it, simply because you might want to be able to access the files contained in that RPM.

RPM does not seem to have this feature out of the box but RPM comes with an handy tool: rpm2cpio , which will let us convert the rpm to a cpio archive file.
Then, we will be able to extract the content of this archive.

rpm2cpio takes only one argument: the rpm file, and outputs to stdout a cpio archive so we can pipe the result into cpio directly.

We then tell cpio to extract the archive with the -i switch and to create leading directories with -d:

$ rpm2cpio compat-gcc-7.3-2.96.110.src.rpm | cpio -id

We can also ask cpio to preserve file modification (-m) and be more verbose (-v).

$ rpm2cpio compat-gcc-7.3-2.96.110.src.rpm | cpio -idmv

You might also simply want to list the content of the rpm. To do so, use the -t switch:

$ rpm2cpio compat-gcc-7.3-2.96.110.src.rpm | cpio -t