IRIS Knowledge Base

   Incorporated Research Institutions for Seismology




How do I extract compressed tar files?

Q:  I am downloading a file through ftp that has '.tar', ‘.tar.gz’, or ‘.tgz’ in the filename. What does this mean and what do I do with it?

A:  This is the Tape Archive (tar) file format that is commonly used to bundle multiple files and directories into a single downloadable file.  Tar files can also be compressed using ‘gzip’, which results in a tag of either .tar.gz or .tgz.

    To unzip a gzipped tar file, use the gnu utility ‘gunzip’ or search on the web for an unzipping utility that works with your system.  To use ‘gunzip’, just include the filename and the result will be a tar file:

    % gunzip myfile.tar.gz
                --- > creates myfile.tar

        To open the tar file, use the Unix ‘tar’ command. First, you might want to look at the contents of the tar file. This example shows how to look at the contents of 'myfile.tar'.  The 't' option is for 'table of contents'.

   % tar tvf myfile.tar

        You will see a listing of files and possibly directory names, and it will indicate where the files in the tar file will be extracted. Note that this does not yet write any files to your disk, so it is safe and good practice to use.

        You will want to verify that the files will extract to the place you want them. If the directory names in the tar file begin with a slash '/' instead of a dot '.' or directory name, it is advised that you think twice about extracting the files, especially if you are running as a privileged user. The reason for this is that the leading slash means the files will be extracted off of your system's root directory and could delete or replace vital system files. It is considered bad practice to have directory names with leading slashes in a tar file.

        When you feel confident about where the files will be extracted, use the command:
      
        % tar xvf myfile.tar
       
        to extract the files.  This one uses the 'x' option, for 'extract'.



Related Articles

No related articles were found.

Attachments

No attachments were found.

Visitor Comments

Article Details

Last Updated
30th of June, 2011

Would you like to...

Print this page  Print this page

Email this page  Email this page

Post a comment  Post a comment

 Subscribe me

Subscribe me  Add to favorites

Remove Highlighting Remove Highlighting

Edit this Article

Quick Edit

Export to PDF


User Opinions

No users have voted.

How would you rate this answer?




Thank you for rating this answer.

Continue