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
gzip Command Reference for CI Scriptsgzip compresses single files with DEFLATE in CI. Reference for -d, -k, -c, and compression levels, plus the t…
zip Command Reference for CI Scriptszip packs files into cross-platform .zip archives in CI. Reference for -r, -j, -q, and -x, plus the missing-b…
unzip Command Reference for CI Scriptsunzip extracts .zip archives in CI. Reference for -o, -d, -q, and -l, plus the interactive overwrite prompt t…
rsync Command Reference for CI Scriptsrsync synchronizes files efficiently in CI deploys and cache restores. Reference for -a, -z, --delete, and th…