Extract a tar archive or file

Contributor Icon Contributed by qmchenry Date Icon July 12, 2006  
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

Previous recipe | Next recipe |
 
  • Kevin
    Juat wanted to know how to open one of these damn things...
    Great - thank you!
  • msf3
    thnx
  • 406notacceptable
    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
blog comments powered by Disqus