tar — Bundle and unbundle files into a single archive (often gzipped) across all 5 shells
Equivalents in every shell
tar -czf archive.tar.gz dir/tar -czf archive.tar.gz dir/tar -czf archive.tar.gz dir/tar -czf archive.tar.gz dirWindows 10 1803+ ships BSD `tar.exe` system-wide; flags match the Unix tool. `Compress-Archive` only does ZIP.
tar -czf archive.tar.gz dirNative `tar.exe` since Windows 10 1803. Pre-1803 has no tar — install 7-Zip or use WSL.
Worked examples
Extract a .tar.gz archive
tar -xzf archive.tar.gztar -xzf archive.tar.gztar -xzf archive.tar.gzList the contents of an archive without extracting
tar -tzf archive.tar.gztar -tzf archive.tar.gztar -tzf archive.tar.gzExtract into a specific directory
tar -xzf archive.tar.gz -C /tmp/outtar -xzf archive.tar.gz -C C:\tmp\outtar -xzf archive.tar.gz -C C:\tmp\outGotchas
- BSD tar (macOS, Windows) and GNU tar differ on long-option spellings and some flags — `--xattrs`, `--owner`, `--group` are GNU-only.
- GNU tar auto-detects compression by extension if you use `-a`; otherwise you must pass `-z` (gzip), `-j` (bzip2), or `-J` (xz) explicitly.
- Tarbombs: archives that extract to the current directory instead of a top-level folder. Always `tar -tzf` first to inspect, or extract into a fresh directory.
- PowerShell `Compress-Archive` cannot read or write `.tar` / `.tar.gz` — only `.zip`. For tarballs, use `tar.exe`.
WSL & PowerShell Core notes
Common tasks using tar
- Compress files into a zip archive
Bundle a folder or set of files into a single `.zip` archive.
- Create a tar archive from a directory
Bundle a directory tree into a single compressed file — for backups, transport, version-snapshot, and the `dist/` artifact step in a build.
- Extract a 7z archive
Unpack a `.7z` file — the highest-ratio common archive format, popular on Windows software downloads and big game/asset bundles.
- Extract a gzip file
Decompress a `.gz` file — single-file compression you encounter in `.tar.gz`, log rotation (`access.log.gz`), and package metadata.
- Extract a tar archive
Unpack a `.tar`, `.tar.gz`, or `.tar.bz2` file into the current directory.
- Extract a zip archive
Unpack a `.zip` file from the command line — the most common archive format on the web, and a frequent source of "how do I unzip on Windows without GUI" searches.
- List the contents of a tar archive
Show what's inside a `.tar`, `.tar.gz`, `.tar.xz`, etc. without extracting — for sanity-checking before unpacking, for grep-searching member names, and for size auditing.