None of the other answers here mention all the caveats of the default tar implementation in Solaris. One such caveat is that it does not support compression by itself. A plain extraction can be achieved through:
gzip -dc < /path/to/the.tar.gz | tar xvf -
Further, if you created the archive by something like
tar cvf - /path/to/directory | gzip -c > the.tar.gz
you will find that extracting this archive always overwrites the original files. This is because Solaris tar does not strip leading / from archive entries upon extraction and has no means of stripping path components. So if you want to be able to extract a second copy of the contents, you will have to create the archive with a slightly different command:
tar cvf - -C /path/to/directory . | gzip -c > the.tar.gz
or
(cd /path/to/directory && tar cvf - .) | gzip -c > the.tar.gz
In the Solaris implementation, the -C switch does not apply to extraction. Assuming the archive was created using one of these two methods or similar, a variant of this second form will allow extraction to an arbitrary location:
gzip -dc < the.tar.gz | (cd /path/to/extraction/point && tar xvf -)
If you have GNU tar installed (/usr/sfw/bin/gtar), it supports compression directly, as well as path-stripping. In this case, the usual options such as
/usr/sfw/bin/gtar xvzf the.tar.gz
will suffice.
tar xf /path/to/t.tar.gzand then change the path back to original dircdcommand in your shell script and run extract and then usecd -to come back to the original dir.-Cswitch as mentioned in the answers.