How to Extract tar.gz Files on Mac, Windows, and Linux

By Hieu Dinh

How to Extract tar.gz Files: The Quick Version

To extract a tar.gz file:

  • Mac: double-click it in Finder, or run tar -xzf file.tar.gz in Terminal.
  • Windows 11: right-click → Extract All, or run tar -xf file.tar.gz in Command Prompt.
  • Linux: run tar -xzf file.tar.gz, or double-click in your file manager.

No extra software is needed on any of them. The rest of this guide covers what a tar.gz actually is, the commands worth remembering, and how to fix the errors people hit most.


What Is a tar.gz File?

A .tar.gz file is two tools stacked together:

  1. tar (short for tape archive) bundles many files and folders into a single .tar file. It doesn't compress anything. It keeps the folder structure, file permissions, ownership, and timestamps, which matters for software that needs executable bits to survive.
  2. gzip compresses that one .tar file into .tar.gz.

.tgz is the same thing with a shorter extension. You'll also see other compressors paired with tar:

ExtensionCompressorTypical use
.tarNoneBundling without compression
.tar.gz / .tgzgzipThe default almost everywhere
.tar.bz2 / .tbz2bzip2Older Linux packages
.tar.xz / .txzxzSmaller files, slower to create (Linux kernel, many distros)
.tar.zstZstandardFast and compact, increasingly common

Because tar compresses the whole bundle as one stream, a tar.gz is often smaller than a ZIP of the same folder, but you can't pull one file out without reading through the archive. tar vs ZIP explains that trade-off in detail.

You'll run into tar.gz files when downloading open-source software, server backups, datasets, and GitHub releases, which offer a Source code (tar.gz) download on every release.


Extract tar.gz on Mac

Finder (double-click)

Double-click the .tar.gz in Finder. Archive Utility extracts it into a folder in the same location. That's all most people need.

If you'd rather use an app with more control (choose destination, handle odd encodings, preview contents), The Unarchiver and Keka both handle tar.gz along with RAR and 7z. Our Keka vs The Unarchiver comparison covers which fits better.

Terminal

# extract into the current folder
tar -xzf archive.tar.gz

# extract into a specific folder (it must already exist)
mkdir -p ~/Desktop/output
tar -xzf archive.tar.gz -C ~/Desktop/output

# see what's inside without extracting
tar -tzf archive.tar.gz

macOS ships with bsdtar, which detects the compression on its own, so tar -xf archive.tar.gz works too, as do .tar.xz and .tar.bz2 files with the same command.


Extract tar.gz on Windows

File Explorer (Windows 11)

Windows 11 version 23H2 and later opens tar.gz natively. Double-click to browse it like a folder, or right-click and choose Extract All. The same update added support for .tar, .tgz, .tar.bz2, .tar.xz, .7z, and .rar.

Built-in tar command (Windows 10 and 11)

Windows has included tar.exe since Windows 10 version 1803. Open Command Prompt or PowerShell in the folder with the archive and run:

tar -xf archive.tar.gz

# or extract to a specific folder
tar -xf archive.tar.gz -C C:\Users\you\Desktop\output

7-Zip

7-Zip handles tar.gz in two passes: the first extraction strips the gzip layer and leaves a .tar; extract that .tar to get the files. It works, but File Explorer or tar.exe is quicker for this format.


Extract tar.gz on Linux

tar -xzf archive.tar.gz

GNOME Files, Dolphin, and most other file managers also offer Extract Here on right-click. For .tar.xz use tar -xJf, and for .tar.bz2 use tar -xjf, or just tar -xf and let GNU tar detect it.


tar Commands Worth Remembering

TaskCommand
Extracttar -xzf archive.tar.gz
Extract and list each filetar -xzvf archive.tar.gz
Extract to a foldertar -xzf archive.tar.gz -C target/
List contentstar -tzf archive.tar.gz
Extract one filetar -xzf archive.tar.gz path/inside/file.txt
Drop the top-level foldertar -xzf archive.tar.gz --strip-components=1
Createtar -czf archive.tar.gz folder/

The letters decode easily: x extract, c create, t list, z gzip, v verbose, f "the file name comes next". The f has to be last in the group because the file name follows it.


How to Create a tar.gz File

tar -czf project.tar.gz project/

On a Mac, add COPYFILE_DISABLE=1 in front:

COPYFILE_DISABLE=1 tar -czf project.tar.gz project/

Without it, macOS stores extended attributes as hidden ._filename files inside the archive. They're harmless on a Mac, but they show up as clutter (and occasionally break build scripts) when someone extracts the archive on Linux or Windows. Also delete stray .DS_Store files before archiving a folder you'll share.


Fixing Common tar.gz Errors

"gzip: stdin: not in gzip format"

The file isn't gzip-compressed, whatever its name says. Check what it really is:

file archive.tar.gz
  • "POSIX tar archive": it's an uncompressed tar. Run tar -xf archive.tar.gz without z.
  • "XZ compressed data" or "Zstandard compressed data": use tar -xf and let tar detect it.
  • "HTML document": the download failed and saved an error page. Download it again, and if you used curl, add -L to follow redirects.

"Unexpected EOF in archive"

The file is truncated, almost always an interrupted download. Compare the file size with the source, or verify the checksum if the project publishes one (shasum -a 256 archive.tar.gz on a Mac).

"Cannot open: Permission denied"

You're extracting into a folder you can't write to. Extract into your home folder with -C ~/somewhere instead of reaching for sudo.

Files spill everywhere

Some archives don't have a single top-level folder, so extracting them scatters files across your current directory. Avoid it by listing first (tar -tzf archive.tar.gz | head) or by always extracting into a fresh folder with -C.


Is It Safe to Extract a tar.gz?

From a trusted source, yes. Modern tar strips leading / from paths and refuses ../ entries that would write outside the target folder, which blocks the classic path-traversal trick. The real risk is what's inside: a tar.gz of software contains programs, and installing or running them is a separate decision from extracting them. Download from the project's official site or release page, and check the published checksum when there is one.

The same caution applies to other archive formats. What is a RAR file covers the RAR-specific risks, which are a bit higher because password-protected RARs slip past email scanners.


tar.gz Won't Shrink Your Media

gzip is excellent at text: source code, logs, CSV files, and JSON often shrink by 70–90%. Videos, photos, and audio are a different story. They're already compressed with codecs like H.264, HEVC, JPEG, and AAC, so gzip finds almost nothing left to squeeze. A 3GB folder of MP4s becomes a 2.97GB tar.gz.

If a folder is too large because of the media inside it, compress the media first and archive second. Compresto re-encodes videos, images, GIFs, and PDFs on a Mac, in batches, and can aim each file at a target size. Then tar or ZIP the much smaller result if you need a single file to send. For background on why archivers and media codecs behave so differently, see lossy vs lossless compression.


FAQ

What is a tar.gz file?

A folder bundled with tar and compressed with gzip. Common for source code, Linux software, backups, and GitHub release downloads.

How do I extract a tar.gz file on Mac?

Double-click it in Finder, or run tar -xzf file.tar.gz in Terminal.

How do I extract a tar.gz file on Windows?

Windows 11: right-click → Extract All. Windows 10 and 11: tar -xf file.tar.gz in Command Prompt.

What does tar -xzf mean?

Extract (x), gzip (z), from this file (f). Add v for verbose output.

Why do I get "gzip: stdin: not in gzip format"?

The file isn't gzip. Run file on it, then use tar -xf without z or re-download it.

How do I create a tar.gz file?

tar -czf archive.tar.gz folder/. On a Mac, prefix with COPYFILE_DISABLE=1.


Bottom Line

You don't need extra software to extract tar.gz files anymore: Finder, Windows 11's File Explorer, and a one-line tar -xzf cover every platform. Learn the four letters (x, c, t, f), extract into a fresh folder, and compress media before archiving if size is the real problem.

Download Compresto for Mac →


Ready to compress your files? Join thousands of creators using Compresto ⚡