Extract a tar archive or file

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: UNIX  

The tar file is the long-time champion of archiving files and even directories of information into a single archive file. However, the first time you face a tar file, it will completely clam up and will not tell you what to do with it. Extracting the contents of a tar file is simple (once you know how).


A tar file is extracted (and created) with the easy-to-remember application tar. While the name is simple, the syntax is a little different than normal UNIX commands. To extract the contents of the file archive.tar, use:

tar xf archive.tar

The x in xf means extract the contents of the archive. The f in xf tells tar to use the next parameter as the filename of the archive. This comes from tar’s history as a tape archiving application (the name tar comes from tape archive). By default, tar wants to read or write to a tape drive, thus the f parameter.

Another couple of nice parameters to know are t and v. The t parameter is used in place of x to list a table of contents of the archive.

tar tf archive.tar

The v parameter can be used with x to list each file in the archive while extracting them.

tar xvf archive.tar

 

6 Comments -


  1. msf3 said on November 3, 2009

    thnx

  2. Anonymous said on February 16, 2010

    FYI, couldn’t find this on your site, but feel this is a good place for this info. For a tar.gz on Solaris 9 I’ve used:

    gunzip -c zip.tar.gz | tar -tf -

    I believe on modern distros you can use:

    gtar -tf zip.tar.gz

  3. Kevin said on February 24, 2010

    Juat wanted to know how to open one of these damn things…
    Great – thank you!

  4. Bavenflaven said on September 8, 2010

    Very Simple. Thanks!

  5. David C. said on September 27, 2010

    Remember that you may need to supercede user root:

    shell> sudo tar xvf

    That way you can have permission to write anywhere on the file system that is needed to extract the files.

  6. Adelnegro said on March 30, 2011

    Perfect. This work for me. I install all like root. Thanks

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -