Please consider this snippet:
tar -Oxvf archive.tgz | grep something
or this:
tar tf archive.tgz > /tmp/x && tar -Oxvf archive.tgz -T /tmp/x | grep something
versus this:
tar tf archive.tgz | xargs -I{} tar -Oxvf archive.tgz {} | grep something
First two snippets are very fast and similar, while third is ~40 times slower (this index is relative to archive contents I guess). Why is that?
The key here is your use of
-I{}in xargs. The man page says:The implied
-L 1makesxargsrun yourtar -Oxvf archive.tgz {}once per file in the archive, rather than running tar once to extract all the files listed on xargs’ stdin.Simplified example of the difference:
Fixed:
Note however that the output of this will not be the same as what you get using
xargs -I{}if the file names given toxargsare not in tar file order (i.e. the same order thattar tlists them in). Thexargs -I{}version will ouptut the files in the order you provided to xargs, whereas this version will output them in tar file order.