Skip to content
Latchkey

tar -x: Extract an Archive (Usage & CI Errors)

tar -x unpacks the members of an archive back onto disk.

Extracting is the consumer side of caching and downloads. The flags decide where files land and whether decompression is automatic.

What it does

tar -x (extract) reads an archive and writes its members into the current directory, recreating the stored directory tree. Modern GNU and BSD tar auto-detect gzip, bzip2, xz, and zstd, so -z is usually optional on extract.

Common usage

Terminal
tar -xf archive.tar
tar -xvf archive.tar.gz                  # verbose, auto-decompress
tar -xf archive.tar -C /opt/app          # extract into a target dir
tar -xzf archive.tar.gz path/to/one/file # extract a single member

Options

FlagWhat it does
-x / --extractExtract members from the archive
-f <file>Read from <file> instead of stdin (use - for stdin)
-C <dir>Change to <dir> before extracting
-v / --verboseList each file as it is extracted
--strip-components=NRemove N leading path components

In CI

Extracting a downloaded release is a tar -x step: curl -L url | tar -xz -C /usr/local/bin --strip-components=1 streams the download, decompresses it, and drops the binary into place without the versioned top-level folder.

Common errors in CI

gzip: stdin: not in gzip format means you passed -z to a file that is not gzip-compressed (often a plain .tar or an HTML error page saved as a .tar.gz). Drop -z or fix the download. tar: Unexpected EOF in archive and tar: short read mean the archive is truncated, usually a partial or failed download; re-fetch and verify the size or checksum.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →