Skip to content
Latchkey

tar: Usage, Options & Common CI Errors

tar packs many files into one archive (and unpacks them again).

tar is everywhere in CI: caches, artifacts, release bundles. The flags are terse and order-sensitive, and a wrong compression flag produces confusing errors.

What it does

tar creates, lists, and extracts archive files, optionally compressing with gzip (-z), bzip2 (-j), or xz (-J). The mode flag (c/x/t) and the -f flag naming the archive are required.

Common usage

Terminal
tar -czf out.tar.gz ./dir              # create gzip archive
tar -xzf out.tar.gz                     # extract gzip archive
tar -xzf out.tar.gz -C /target/dir      # extract into a dir
tar -tzf out.tar.gz                     # list contents
tar -czf - ./dir | ssh host 'tar -xzf - -C /dst'

Options

FlagWhat it does
-c / -x / -tCreate / extract / list
-f <file>Use this archive file (required; - = stdin/stdout)
-z / -j / -Jgzip / bzip2 / xz compression
-C <dir>Change to dir before acting
-vVerbose file list

Common errors in CI

tar: out.tar.gz: Cannot open: No such file or directory - the archive path is wrong or the build that created it failed. "gzip: stdin: not in gzip format" / "This does not look like a tar archive" means you used -z on a non-gzip file (e.g. a plain .tar, or an HTML error page a download saved). "tar: Removing leading "/" from member names" is a harmless warning. On BSD/macOS tar, GNU-only flags like --owner differ.

Related guides

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