How to Extract and Unzip .tar.gz files

Extract and unzip .tar.gz files on Linux, Windows and MacOS

T
Written by Team Pressidium
Updated this week

Several operations involving multiple files might store and compress the result in a .tar.gz format. It's an alternative to the ubiquitous ZIP format and popular among backup and archiving tools, especially in Unix or Linux operating systems.

What is a .tar.gz or .tgz file?

A .tar.gz or .tgz file is a compressed archive file format that is a combination of two other archive formats, namely TAR (tape archive) and GZIP. The TAR format is used to store multiple files into one archive, while GZIP is used to compress the data in the archive to reduce its size. The .tgz file format is typically used on Unix and Linux operating systems, but can also be opened on other platforms, including Windows and macOS, with the help of specialized software.

To extract the contents of a .tgz file, you can use a tool such as tar (on Unix and Linux) or a file compression utility like 7-Zip or WinRAR (on Windows). Once the file has been extracted, you will have access to all of the files and folders contained within the archive.

How to extract a .tar.gz file on Linux?

To extract a .tar.gz file on Linux, you can use the "tar" command in the terminal. Here is the general syntax:

tar -xvzf filename.tar.gz

Here is a brief explanation of the options used:

  • -x: This option tells tar to extract the contents of the archive.

  • -v: This option is for verbose output, which means that tar will display a list of the files being extracted as it does so.

  • -z: This option tells tar to decompress the archive using gzip.

  • -f: This option is used to specify the archive file to extract.

So, for example, if you have a .tar.gz file named mywebsitebackup.tar.gz, you would extract its contents using the following command:

tar -xvzf mywebsitebackup.tar.gz

This will extract the contents of the archive into the current directory. If you want to extract the contents of the archive to a specific directory, you can use the following syntax:

tar -xvzf mywebsitebackup.tar.gz -C /path/to/directory

This will extract the contents of the archive into the specified directory.

You can learn more about the full options by consulting the related man page of your Linux distribution.

How to extract a .tar.gz file on Windows?

To extract a .tar.gz file on Windows, you will need a file compression tool that supports this format. There are many such tools available, with a friendly graphical user interface, including 7-Zip (open source) and WinRAR (free trial). Windows 10 also includes a build in tar utility that can be used via the command line / terminal.

Here's how you can extract a .tar.gz file using 7-Zip:

  1. Download and install 7-Zip if you don't have it installed already.

  2. Right-click on the .tar.gz file you want to extract and select "7-Zip" > "Extract Here."

  3. The contents of the archive will be extracted to the same directory as the archive. The now uncompressed .tar file should be visible in the directory listing.

  4. Locate the .tar file, right click and select "7-Zip" > "Extract Here."

  5. The contents of the tar file will be extracted to the same directory as the archive.

Here's how you can extract a .tar.gz file using WinRAR:

  1. Download and install WinRAR if you don't have it installed already.

  2. Right-click on the .tar.gz file you want to extract and select "Extract files..."

  3. In the "Extraction path and options" section, select the folder where you want to extract the contents of the archive.

  4. Click the "OK" button to extract the contents of the archive.

Here's how you can extract a .tar.gz file using the native built in tar command in Windows 10:

To use the native "tar" command on Windows 10, you will need to have Windows 10 version 2004 or later, and use the Command Prompt / Windows Terminal.

  1. Open the Start menu and type "Terminal."

  2. Click on the "Windows Terminal" app to open a terminal window.

  3. Change to the directory where the file is located using the cd command.

  4. In the terminal window, type the following command to extract the .tar.gz file:

tar -xvzf mywebsitebackup.tar.gz

This will extract the contents of the archive into the current directory. If you want to extract the contents of the archive to a specific directory, you can use the following syntax:

tar -xvzf mywebsitebackup.tar.gz -C c:\path\to\directory

Regardless of which tool you use, the process should be straightforward and will allow you to access the contents of the .tar.gz archive on your Windows machine.

How to extract a .tar.gz file on Mac OS?

On MacOS, you can extract a .tar.gz file using the Terminal application and the built-in "tar" command. Here's how:

  1. Open the Terminal application. You can find it in the Utilities folder within the Applications folder.

  2. Navigate to the directory where the .tar.gz file is located. For example, if the file is located on your Desktop, you can type the following command:

bash
cd ~/Desktop

Use the following command to extract the .tar.gz file:

tar -xzvf mywebsitebackup.tar.gz

This will extract the contents of the .tar.gz file into the current directory. If you want to extract the contents of the archive to a specific directory, you can use the following syntax:

tar -xzvf mywebsitebackup.tar.gz -C /path/to/directory

This will extract the contents of the archive into the specified directory.

And that's it! The contents of the .tar.gz file should now be available in the specified directory.

-40% Spring Offer

Pressidium Managed WordPress Hosting

Sign up now and enjoy a 40% discount on your first bill!

Did this answer your question?