What a tar file is and why you need to extract it

A tar file is a container that holds multiple files and folders bundled together, often compressed to save space. The name comes from "tape archive" — it was originally used to back up data to magnetic tape. Today, tar files are common on Linux, Mac, and Unix systems, and you'll encounter them when downloading source code, software, or backups.

When you download a tar file, you cannot use the individual files inside it until you extract them. Extraction unpacks the container and puts all the files back into separate folders on your computer where you can actually open and use them. The process is straightforward once you know which tool to use — it depends on whether your tar file is also compressed.

Key Takeaways

  • A tar file ending in .tar contains uncompressed files; one ending in .tar.gz or .tgz is compressed and requires decompression during extraction.
  • On Mac and Linux, you extract tar files using the Terminal with the command tar -xf filename.tar or tar -xzf filename.tar.gz.
  • On Windows, you can use built-in tools like 7-Zip or third-party software like WinRAR, or use Windows Subsystem for Linux if you prefer the command line.
  • After extraction, check the new folder that appears on your desktop or in your file manager — this folder contains all the files that were inside the tar archive.

Extracting a tar file on Mac or Linux using Terminal

The fastest way to extract a tar file on Mac or Linux is through Terminal, which comes built into both systems. Open Terminal (on Mac, search for it in Spotlight; on Linux, right-click your desktop and select "Open Terminal Here" or use your application menu). Navigate to the folder where your tar file is located, or drag the tar file into the Terminal window to show its path.

For an uncompressed tar file ending in .tar, type this command and press Enter:

tar -xf filename.tar

Replace "filename.tar" with the actual name of your file. The -x flag means "extract" and -f means "from file". For a compressed tar file ending in .tar.gz or .tgz, use this command instead:

tar -xzf filename.tar.gz

The -z flag tells tar to decompress the file as it extracts. In both cases, a new folder will appear in the same location as your tar file, containing all the extracted contents. You do not need to do anything else — the extraction happens automatically.

Extracting a tar file on Windows

Windows does not include a built-in tar tool, but you have several options. The easiest is to use 7-Zip, a free program that handles tar files natively. Download it from 7-zip.org, install it, then right-click your tar file and select "7-Zip" → "Extract Here". A folder with all the contents will appear immediately.

If you already have WinRAR installed (a paid but widely-used archive tool), right-click the tar file and select "Extract to [foldername]". WinRAR handles both compressed and uncompressed tar files automatically.

If you prefer not to install new software, Windows 10 and later include Windows Subsystem for Linux (WSL), which gives you access to Linux commands including tar. To set this up, open PowerShell as Administrator, type wsl --install, and follow the prompts. Once installed, you can use the same Terminal commands listed above. This is more complex than using 7-Zip, so only choose this route if you plan to work with tar files regularly.

Understanding tar file naming and compression

The file extension tells you what kind of tar file you have. A file named archive.tar is uncompressed — it is just files bundled together. A file named archive.tar.gz or archive.tgz is compressed with gzip, which makes it smaller for downloading but requires decompression. A file named archive.tar.bz2 uses a different compression method called bzip2.

On Mac and Linux, the tar command handles all three automatically if you use the right flag. For .tar.bz2 files, use tar -xjf filename.tar.bz2 (the -j flag handles bzip2). On Windows with 7-Zip or WinRAR, you do not need to think about this — the program figures out the compression type and extracts correctly.

If you are unsure what type of tar file you have, look at the full filename. If it ends in .tar, it is uncompressed. If it ends in .gz or .tgz, it is gzip-compressed. If it ends in .bz2, it is bzip2-compressed. The extraction method depends on this.

What to do after extraction

After you extract a tar file, look for a new folder in the same location where the tar file was. Open this folder — inside you will find all the files and subfolders that were archived. If the tar file contained a single project or program, there is usually one main folder with everything organized inside it.

At this point, you can delete the original tar file if you want to save space, or keep it as a backup. The extracted files are now ready to use. If the archive contained source code or an installer, follow the instructions that came with it. If it contained a backup, you can now access the backed-up files normally.

If extraction fails or you see an error message, the most common cause is a typo in the filename or using the wrong flag for the compression type. Double-check the exact filename and make sure you are using -xzf for .tar.gz files and -xjf for .tar.bz2 files.

Extracting nested tar files

Occasionally you will extract a tar file and find another tar file inside it. This happens when someone created a tar archive and then compressed that archive again. Simply extract the inner tar file using the same steps — it will unpack into another folder with the actual files you need.

On rare occasions, you might find a tar file inside a tar file inside another tar file. This is unusual but the solution is the same: extract each layer one at a time. Each extraction creates a new folder, so you will always know which files belong together.

Frequently Asked Questions

Can I preview what is inside a tar file before extracting it?

Yes. On Mac and Linux, use tar -tf filename.tar to list all files without extracting. On Windows with 7-Zip, right-click the tar file and select "7-Zip" → "Open Archive" to browse the contents. This is useful if you want to see the folder structure before you extract.

What if the tar file is corrupted or will not extract?

Try downloading the file again — the download may have been interrupted. If it still fails, check that you are using the correct extraction command for the file type (.tar versus .tar.gz). If you are on Windows and using 7-Zip, try WinRAR instead, as different tools sometimes handle corrupted files differently. If the file came from an untrusted source, it may be intentionally broken.

Do I need to keep the tar file after I extract it?

No. Once extraction is complete, the tar file and the extracted folder are separate. You can delete the tar file to free up space. Keep it only if you want a backup copy of the original archive or if you need to extract it again on another computer.

Why is my extracted folder so large if the tar file was small?

Compressed tar files (like .tar.gz) are much smaller than their contents because compression removes redundancy from the data. When you extract, the files return to their original size. This is normal and expected.

Can I extract just one file from a tar archive instead of everything?

Yes, on Mac and Linux. Use tar -xf filename.tar path/to/specific/file, replacing the path with the file you want. You can see the exact path by running tar -tf filename.tar first. On Windows, use 7-Zip to open the archive, find the file you want, and drag it out to your desktop.