Skip to content
Latchkey

tar Command Reference for CI Scripts

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.

Common flags/usage

  • -c / -x / -t: create / extract / list
  • -f FILE: name the archive (required; - means stdin/stdout)
  • -z / -j / -J: gzip / bzip2 / xz compression
  • -C DIR: change into DIR before acting
  • -v: verbose file list

Example

shell
tar -czf "cache-${GITHUB_SHA}.tar.gz" -C "${HOME}/.cache" .
mkdir -p "${HOME}/.cache"
tar -xzf cache.tar.gz -C "${HOME}/.cache"

In CI

"gzip: stdin: not in gzip format" means you used -z on a non-gzip file (often a plain .tar or a saved error page). "Cannot open: No such file" usually means the build that created the archive failed. macOS/BSD tar differs from GNU tar on flags like --owner.

Key takeaways

  • Use -czf to create and -xzf to extract gzip archives; the -f flag is mandatory.
  • -C changes directory before acting, which keeps archive paths clean.
  • A "not in gzip format" error means the file is not gzip or the download failed.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →