Skip to content
shellmap

tarBundle and unbundle files into a single archive (often gzipped) across all 5 shells

Equivalents in every shell

Bashunix
tar -czf archive.tar.gz dir/
Zshunix
tar -czf archive.tar.gz dir/
Fishunix
tar -czf archive.tar.gz dir/
PowerShellwindows
tar -czf archive.tar.gz dir

Windows 10 1803+ ships BSD `tar.exe` system-wide; flags match the Unix tool. `Compress-Archive` only does ZIP.

cmd.exewindows
tar -czf archive.tar.gz dir

Native `tar.exe` since Windows 10 1803. Pre-1803 has no tar — install 7-Zip or use WSL.

Worked examples

Extract a .tar.gz archive

Bash
tar -xzf archive.tar.gz
PowerShell
tar -xzf archive.tar.gz
cmd.exe
tar -xzf archive.tar.gz

List the contents of an archive without extracting

Bash
tar -tzf archive.tar.gz
PowerShell
tar -tzf archive.tar.gz
cmd.exe
tar -tzf archive.tar.gz

Extract into a specific directory

Bash
tar -xzf archive.tar.gz -C /tmp/out
PowerShell
tar -xzf archive.tar.gz -C C:\tmp\out
cmd.exe
tar -xzf archive.tar.gz -C C:\tmp\out

Gotchas

  • 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

pwshPowerShell Core does not wrap `tar` in a cmdlet — it just relies on the system `tar.exe` (Windows 10 1803+, BSD-flavored) or `/usr/bin/tar` (Linux GNU, macOS BSD). The same `tar -czf` line works in pwsh on every platform, which is unusual for an archive tool.
WSLWSL ships GNU `tar`. To unpack a Windows-side archive, `tar -xzf /mnt/c/Users/me/foo.tar.gz` works but extracted permissions follow Linux mode bits; if the result is consumed by Windows tools, set `umask 022` before extracting and avoid `--preserve-permissions`.

Common tasks using tar

Related commands