views:

1060

answers:

5

when I download a .tar.gz file, I open it with two commands, first gunzip and then tar.

Is it possible to open it with just one command?

+10  A: 
tar xzf file.tar.gz

The letters are:

  • x - extract
  • z - gunzip the input
  • f - Read from a file, not stdin
unwind
This is correct. The only thing that I would add is that z usually only works on gnu tar. The typical UNIX tar won't have this in my experience at least.
Jon
+4  A: 

You can use tar with a "z" argument

tar xvfz mytar.tar.gz
WiseTechi
what does the 'v' argument do?
Nathan Fellman
v stands for "verbose" - I like to see what my command is doing
WiseTechi
in fact, for extract `x` mode, you don't have to specify `z` with newer tar -- it is autodetected (GNU tar 1.20+).
kaizer.se
+1  A: 

If you don't have gnu tar it is still possible to open the file in a single step (although technically still two commands) using a pipe

zcat file.tar.gz |tar x
Martin Beckett
A: 

The only thing that I would add is that z usually only works on gnu tar. The typical UNIX tar won't have this in my experience at least. – Jon Mar 16 at 16:19

The z option works well on my OS-X 10.5 as well.

When it comes to memorizing, I think it´s easy to think of what you want and not just some letters.

  1. If you want to create an archive, then c will be the first option, else x will be the first option if you want to e**x**tract.
  2. If you want to compress/decompress with the g**z**ip/gun**z**ip program, then the next option should be z for zip. (All archives ending with .gz must be unzipped with the z option)
  3. The last mandatory option is f for the file.

Then you usually end up with these two commands:

  • tar czf file.tar.gz /folder_to_archive/*
  • tar xzf file.tar.gz
Espen
OS X uses GNU tar.
micmoo
A: 

On Windows Try the tartool utility http://tartool.codeplex.com/

The code is open source and uses SharpZipLib library.

Disclaimer : I am the author of this utility.