• About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings
Monday, November 2, 2026
  • Login
PacketNebula
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download
No Result
View All Result
PacketNebula
No Result
View All Result
Home Sysadmin

How to extract and create tar.gz archives (tar)

by Stéphane Cardon
7 October 2026
in Sysadmin
0
Four magnetic tape data cartridges: Sony LTO Ultrium 3, Exabyte 8mm, TDK DDS-3 and a Verbatim data cassette

Image: Mister rf / Wikimedia Commons, CC BY-SA 4.0

Share on FacebookShare on Twitter

Someone hands us a release.tar.gz and the clock's already ticking. Two commands cover almost everything: tar -xzf archive.tar.gz unpacks one, tar -czf archive.tar.gz folder builds one. The flags look cryptic but they read as words once you see it: x for eXtract or c for Create, z for gunZip, f for the File whose name comes next. Add -C to drop the files into a specific folder instead of wherever you happen to be standing. Works on Linux and macOS out of the box, and on Windows 10 and 11 too, where tar now ships built in. Below, each command with a real example, plus the one-letter swaps for .tar.bz2 and .tar.xz. And how to list what's inside before you unpack. Do that one.

The short answer

tar -xzf archive.tar.gz extracts and tar -czf archive.tar.gz folder creates. Check the contents first with tar -tzf archive.tar.gz. The flags read as eXtract or Create, gunZip, File. Add -C /target to pick where the files land.

tar -xzfextract an archive
tar -czfcreate one
tar -tzflist what’s inside
Answer card showing tar -xzf to extract a tar.gz and tar -czf to create one.
Two commands cover most of it. The flags spell out what they do once you know the trick.

Extract a .tar.gz

Linux
tar -xzf archive.tar.gz

It unpacks into whatever folder we’re standing in, which isn’t always where we wanted it. To send it somewhere specific (the folder must already exist):

Linux
tar -xzf archive.tar.gz -C /opt/app

Create a .tar.gz, and look before you leap

Point it at a folder, or name the files one by one:

Linux
tar -czf backup.tar.gz myfolder/

Some archives unpack a hundred loose files straight into your current directory. A tarbomb. List the contents first and it never catches you:

Linux
tar -tzf archive.tar.gz
Terminal showing tar -czf creating an archive, tar -tzf listing its contents, then tar -xzf extracting into a target folder.
Create, list, extract. The list step is the one people skip and regret.

Other compression, and doing it on Windows

Same verbs, one different letter. Use -j for .tar.bz2 and -J (capital) for .tar.xz. xz squeezes smaller and runs slower, which is why distros love it for downloads. On a slow laptop we’ve cursed it more than once.

No third-party tool needed anymore: tar ships in Windows 10 and 11, same flags, in both Command Prompt and PowerShell. Plain .zip files are the exception there; Expand-Archive is the native route for those.

Always look inside before extracting an archive you didn’t create. A well behaved tarball puts everything in one folder, but nothing enforces that, and one that scatters files across your current directory is a genuine mess to clean up. It even has a name, a tar bomb.

Linux and macOS
tar tzf archive.tar.gz | head

If the listing shows loose files rather than a single top level folder, GNU tar can wrap them for you with --one-top-level, which creates a directory named after the archive and puts everything inside. Otherwise extract somewhere else entirely with -C, which takes a target directory and is the habit worth building.

Linux and macOS
tar xzf archive.tar.gz -C /tmp/unpack

Saying the letters out loud while you type them isn’t elegant, but it works. xzf and czf differ by a single character, and one of them cheerfully overwrites the archive you meant to read.

Frequently asked questions

What do the letters in tar -xzf mean?

Each one is a switch. x extracts (swap in c to create), z handles the gzip layer for .gz files. f says the next word is the filename, so tar -xzf reads as extract, gunzip, from this file. Plenty of us still type tar xzf without the dash out of old habit, and that works too.

How do I extract a tar.gz into a specific folder?

Add -C and the target: "tar -xzf archive.tar.gz -C /opt/app". One catch: the folder has to exist first, so run "mkdir -p /opt/app" before it if needed. Leave -C off and tar dumps everything into the current directory.

How do I see what’s inside without extracting?

Swap the x for t (list): "tar -tzf archive.tar.gz". It prints every path inside, so you know whether it's about to spray files all over your current folder. That's the classic tarbomb, and we've all met one.

What about .tar.bz2 or .tar.xz files?

Same commands, one different compression letter: -j for .tar.bz2, -J (capital) for .tar.xz. Modern tar can also auto-detect from the name, so "tar -xf archive.tar.xz" usually just works whatever the compression.

Tags: guidelinux
ShareTweet
Previous Post

How to generate an SSH key (ssh-keygen)

Next Post

How to download a file and test an API with curl

Stéphane Cardon

Stéphane Cardon

Network cybersecurity engineer: architecture, LAN and WLAN, system administration. He runs PacketNebula, where he publishes the tools and answers he wanted for his own work.

Next Post
Hands typing on a backlit laptop keyboard in the dark

How to download a file and test an API with curl

Free tools

  • IPv4 subnet calculator
  • DNS lookup
  • SSL certificate checker
  • HTTP headers checker
  • SPF, DKIM and DMARC checker
  • JWT decoder
  • Cron expression builder
  • Chmod calculator
  • Password generator

All 24 tools →

Guides to keep handy

  • Flush the DNS cache on Windows
  • Kill the process using a port
  • Generate an SSH key
  • Secure a new Ubuntu VPS
  • Find files on Linux
  • Extract and create tar.gz

More guides →

Who writes this

Stéphane Cardon, network cybersecurity engineer. Architecture, LAN and WLAN, system administration. PacketNebula holds the tools and answers he wanted for his own work.

About this site →

  • About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings

Copyright © 2026 Stephane Cardon.

No Result
View All Result
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download

Copyright © 2026 Stephane Cardon.

Cookies, your call

We use Google Analytics to see which pages get read. Once our AdSense application is approved, articles and guides will carry Google ads. Nothing runs until you say yes, and nothing runs on the tool pages. Details