How to open a tar file in Unix or Linux

A lot of the downloadable Linux or Unix files found on the internet are compressed using a tar or tar.gz compression format. So, knowing how to open or untar these compressed files becomes very important. In the following examples, we will explain how to untar both popular formats and how to extract the contents to a different directory.

How to open or Untar a “tar.gz” file in Linux or Unix

  1. Open a terminal window ctrl+alt+t
  2. From the terminal, change directory to where your .tar.gz file is located,
    (replacing file_name.tar.gz with the actual name of your file)

    cd /directory_path/file_name.tar.gz

  3. To extract the contents of the tar.gz file to the current directory, type

    tar -zxvf file_name.tar.gz

    NOTE: You can specify a different directory to extract to using the -C parameter and path to the directory as follows:

    tar -C /myfolder -zxvf file_name.tar.gz

How to open or Untar a “tar” file in Linux or Unix

  1. From the terminal, change to the directory where your .tar file has been downloaded.
  2. To extract or untar the file to the current directory, type the following,
    (Making sure to replace file_name.tar with the actual filename)

    tar -xvf file_name.tar

    Or to extract to another directory, type

    tar -C /myfolder -xvf file_name.tar