Decompressing and extracting tar.gz archives

Tar.gz compressed archives are the most common way that software is distributed for use on Unix/Linux systems. We’ve learned another way to unpack these files from the command line when using Solaris, the distribution that Joyent uses for their shared hosting.

For most systems, the command for decompressing and extracting tar.gz files is something like this:

tar -xzf file.tar.gz

In this case, the -x indicates extraction, -z indicated to run through gzip, and -f to save the results to the filesystem.

However, this does not work on some systems, in our case when working with Solaris. The alternative command in this case is:

gzip -dc file.tar.gz | tar xf –

This decompresses the file and then pipes it to tar for extraction.