Given the fact that you have a .tar.gz file, the first way you tried, with the -C option, will work just fine:
tar xvzf /dir/to/file.tar.gz -C /dir/to/output/
tar
calls gzip to decompress, and then extracts the files from the tar stream. gzip
can only decompress, so gunzip file.tar.gz
would simply leave with the decompressed file.tar
, on which you would then need to tar xvf file.tar
. The z
option of tar
is simply a shortcut to do the decompression with gzip along with extracting the files.
If you want to just decompress a .gz file (as opposed to extracting a .tar.gz file) to a different directory, simply pipe there. E.g. gzip -dc < file.gz > /somewhere/file
.