Extract a gzip compressed tar archive in Linux

Posted October 3, 2003 by Quinn McHenry in Linux

The version of tar in most Linux distributions supports gzip compression. This means that a gzipped tar file can be extracted in one simple command.

To extract the archive filename.tar.gz into the current directory:

tar xzf filename.tar.gz

If this fails, the version of tar may not support gzip compression. In this case, you can use the traditional two-stage command:

gzip -dc filename.tar.gz | tar xf -


About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

  • santhosh

    i got the following error when i extracted.
    gzip: stdin: not in gzip format
    tar: Child returned status 1
    tar: Error exit delayed from previous errors.
    Plz suggest any way to extract in linux?

  • Anonymous

    santhosh are you sure its not a bzip not gzip

  • Anonymous

    Sorry Bozzzzzzzz! it won’t worked for me

  • sikat ang pinoy

    It won’t work for me I think gunzip is another option to unzip gzip file.

  • Bubu

    good stuff

  • Rahul B

    gunzip file.tar.gz

    it will give file.tar

    then type command tar -xvf

  • Rahulbiliye

    gunzip file.tar.gz
    u get file.tar
    tar -xvf file.tar

    • S_raparty

      Good thanx Rahul 

  • Thiyagarajan Veluchamy


  • Pete

    one liner
    tar -zxvf file.tar.gz

    extracts all to current dir

  • hiba

    if I need to extract in .gzip format in linux what is the suitable command. please can you help me