Decompress and extract a tgz or tar.gz archive in a single step
Posted by Quinn McHenry in UNIX
Compressed UNIX tar archives (typically tar.gz or .tgz extensions) can be extracted in a single command. This is faster and works with less disk space available.
To extract the compressed tar archive target.tar.gz into the current working directory with:
gzip -dc target.tar.gz | tar xf -
If the file was compressed with bzip2 (i.e., .tar.bz2), you can substitute the bzip2 command for gzip.
If the archive was compressed with the UNIX compress command (archive ending in .Z) you can use:
zcat target.tar.Z | tar xf -
About Quinn McHenry
View more articles by Quinn McHenry
The Conversation
Follow the reactions below and share your own thoughts.




October 03, 2008 at 12:38 am, Jeff said:
this is easier:
# tar xvzf target.tar.gz
November 28, 2010 at 10:15 am, perk said:
exactelly true ur the best……
October 03, 2008 at 12:48 am, Quinn McHenry said:
Oh, yeah, I’ll admit that command is easier, although back in 2003 it only seemed to work in some linux distros. I was using Solaris (probably 7 at the time) and that tar didn’t have that cool option. I don’t have a Solaris box handy now, but I would be surprised if that hadn’t crept its way in yet.
Should be noted that ‘j’ in place of ‘z’ in your command will extract a bz2 archived tar file. J. Really. I guess all the appropriate letters were on vacation.
March 02, 2011 at 10:10 am, Karen said:
Your original method was correct. The tar commands on AIX, HP-UX and Solaris do not accept the options z or j.
For those lazy GNU people, you can actually omit the letter too, as GNU tar will work out what compression algorithm was used. But the original post done this is the most portable and professonal way
May 15, 2011 at 4:39 am, Anonymous said:
Thanks for adding that updated information.
April 29, 2010 at 7:21 am, Anonymous said:
i got following error when i am trying to run the above command.
/ITS/release/hawai > gzip -dc sx51_wp4_hp_itanium_dev.tar.gz | tar xf -
tar: ./bin/cob32 – cannot create
tar: ./bin/cob64 – cannot create
tar: ./bin/cobffnd32 – cannot create
tar: ./bin/cobffnd64 – cannot create
tar: ./bin/cobffnd32_t – cannot create
tar: ./bin/cobffnd64_t – cannot create
directory checksum error
June 04, 2010 at 6:30 pm, JayJay said:
Try typing sudo before gzip
March 16, 2011 at 2:37 pm, Shadur said:
You’re not allowed to create a directory bin/cob32 in /ITS/release/hawai.
February 20, 2011 at 10:42 pm, Cyril said:
I am under Solaris 10. tar command still has no “z” option.
Your tip comes in handy! Thanks.
December 23, 2011 at 7:49 am, JEYAPRAKASH said:
BOSS VERY VERY THANK IT’S VERY VERY HELPFUL FOR ME
THAKS ONCE AGIAN