I was wondering the possible best time case solutions to extract each RPM files from a list of TAR bundle and get the package information from those files.

So, I have a list of tar bundles in a directory, containing at least one RPM. For these, I have tried the simplest solution to loop over, extract and then peak into each RPM package using a bash script, which is taking a significant amount of time given the TAR bundles are over 20+.

I also tried bulk extraction using cat *.tar | tar -xvf - -i, then rpm -qp #list of files to get the package names which gave me an improvement over my last approach.

I know that I could peek into TAR bundle and get the .rpm file name, but since the name of the file containing a package has nothing to do with the name of the package, I need to check the RPM package as well.

The closest solution I could attempt was:

# given tarball-containing-wget-rpm-package.tar.gz contains wget.rpm 

bash$ time (cat tarball-containing-wget-rpm-package.tar.gz|gunzip|tar --wildcards --extract '*.rpm' --to-stdout|rpm -qp /dev/stdin)

real    0m0.049s
user    0m0.044s
sys     0m0.004s

which is pretty quick, but doesn't give right info if a TAR bundle contains more than one RPM files.

So, what I’m asking is:

  • Can I bulk extract all TAR file to stdout and peek in the RPM files then?
  • Can I perform this operation without extracting the files from TAR bundle?
  • How can I modify the above command to work with a single TAR bundle containing multiple RPM?
  • The manpage states that the -p option expects a single package file, so I don't think you'll be able to use this approach. As a side note, you can replace cat filename|gunzip|tar with tar -z -f filename if you have GNU tar.
    – Haxiel
    Commented Apr 17, 2020 at 11:59
  • @Haxiel rpm -qp --queryformat '%{NAME}\t%{VERSION}\t%{RELEASE}\n' a1.rpm a2.rpm a3.rpm is working by giving package information. Commented Apr 17, 2020 at 13:06

1 Answer 1


Given that the rpm command can correctly process one file from stdin and fails when there are mutiple files involved, the following approach is a potential solution.

With GNU tar, you can use the --to-command option to send each file's content to the rpm command.

tar -zf tarball.gz --wildcards --extract '*.rpm' --to-command='rpm -qp /dev/stdin'

From the manual:


Extract files and pipe their contents to the standard input of command. When this option is used, instead of creating the files specified, tar invokes command and pipes the contents of the files to its standard output. The command may contain command line arguments (see Running External Commands, for more detail).

Notice, that command is executed once for each regular file extracted. Non-regular files (directories, etc.) are ignored when this option is used.

  • @TanmayBaranwal if you have a new question, please post it separately. You can link back to this one if it adds helpful context.
    – terdon
    Commented Jul 6, 2020 at 11:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .