Search code examples
gziptarzcat

What is the advantage and/or disadvantage of directing stream to zcat for tar.gz extraction?


I have occasionally come across this pattern for extracting a "tarball" file: zcat < some-archive.tar.gz | tar xf -

How is this different from tar -xzf some-archive.tar.gz ...aside from the obvious syntax?

And what is an example use case for the more complicated zcat implementation?

I was not able to see how these two commands are substantially different by observation nor able to find an answer through an internet search thus far.


Solution

  • The first one is the old way, and the second one is the new way. tar didn't use to have the ability to either run gzip on its own or have gzip built in, as it does now. So you had to run the decompressor separately and pipe it in to tar.

    Even when it did have the ability to run gzip, you needed to tell it which decompressor to use, e.g. with the z option for gzip. So it was tar -xzf.

    Now tar has gzip and others built-in, and tar automatically detects the format and uses the correct decompressor without you having to tell it. Your second form is generally preferred.