Skip to content
shellmap

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.

How to list the contents of a tar archive in each shell

Bashunix
tar tf archive.tar

`t` = list (vs `x` extract / `c` create). `f FILE` = archive file. `v` adds verbose (permissions, owner, size, mtime — like `ls -l`). Modern GNU tar AUTO-DETECTS compression from file extension or magic bytes — `tar tf archive.tar.gz` works without explicit `z`.

Zshunix
tar tf archive.tar
Fishunix
tar tf archive.tar
PowerShellwindows
tar.exe tf archive.tar

pwsh has NO native `Get-TarContent` — relies on bundled `tar.exe` (Win10 1803+). For pwsh 7 cross-platform, `tar` is the system's tar on Linux/macOS. No pwsh-native API for tar; .NET's `System.Formats.Tar` (added .NET 7) is the underlying API if you need to script.

cmd.exewindows
tar.exe tf archive.tar

Win10 1803+ bundled BSD libarchive `tar.exe`. Works on `.tar`, `.tar.gz`, `.tar.xz`, `.tar.bz2`, `.zip`, and more (libarchive auto-detects). Pre-Win10, install GnuWin's tar or use 7z (`7z l archive.tar`).

Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.

Gotchas & notes

  • **Flag combinations for tar are notoriously cryptic** — `tar tvf` is the most-typed: `t` list, `v` verbose, `f` file follows. Modern GNU tar (Linux) auto-detects compression — `tar tvf archive.tar.xz` works without `-J`. macOS uses BSD `tar` (libarchive) which ALSO auto-detects. So in 2026, the only reason to specify compression is for very old systems or when you want to FORCE a specific decoder. Legacy still seen in tutorials: `tar ztvf` (gzip), `tar Jtvf` (xz), `tar jtvf` (bzip2) — these still work but auto-detection makes them redundant.
  • **Filtering output for grep-able patterns**: `tar tf archive.tar.gz | grep "*.txt"` lists only .txt members. Tar itself can filter on extraction with `--wildcards "*.txt"` (GNU) or pattern argument (`tar xf archive.tar "*.txt"`). For `find`-style member listing with size info: `tar tvf archive.tar.gz | awk '{print $3, $6}'` shows size + name only. For a "tree-style" view of a tarball: `tar tf archive.tar.gz | tree --fromfile -` (`--fromfile` reads paths from stdin, `tree` renders tree from path-list — useful for inspecting deeply-nested archive structures).
  • **Member count + total size at a glance**: `tar tvf archive.tar.gz | awk '{sum+=$3; n++} END {print n, "files", sum/1024/1024, "MB uncompressed"}'`. The compressed size is `du -h archive.tar.gz`; the uncompressed-size sum gives the on-disk footprint after extract. The ratio reveals how compressible the contents are: text-heavy archives compress 5-10x; pre-compressed media (jpg, mp4) compress almost 0x. A 100 MB archive that expands to 5 GB suggests zipbomb territory — see `extract-zip-archive` notes.
  • **Listing a SPECIFIC sub-path**: `tar tf archive.tar.gz "/path/inside/archive/*"`. Many tar versions accept member-glob arguments after the archive. To extract just a subdirectory: `tar xf archive.tar.gz dir/subdir/` — DOES NOT need to extract the entire archive first. For grep-searching CONTENTS of text files inside a tar: `tar xzf archive.tar.gz -O | grep PATTERN` (`-O` writes to stdout instead of files — concatenates all members' contents). For a single specific member: `tar xzf archive.tar.gz --to-stdout path/to/file.txt`.
  • **The `tar` command line is the GNU/BSD divergence canonical example**: GNU tar supports `--checkpoint=1000 --checkpoint-action=dot` (progress dots every 1000 files), `--delete` (modify in-place), `--remove-files` (delete after archiving), `--exclude=PATTERN`, `--show-transformed-names`. BSD tar (macOS, FreeBSD) does NOT support `--delete` (must recreate the archive without the unwanted files). `--exclude` works on both. For scripts that need to run on macOS and Linux: stick to the common subset (`-t`/`-x`/`-c`/`-f`/`-v`/`--exclude`/`--strip-components`), or call `brew install gnu-tar` on macOS (provides `gtar`).

Related commands

Related tasks