Skip to content
Latchkey

tar with stdin/stdout: Piping Archives (CI Errors)

tar -f - streams the archive through a pipe instead of a file on disk.

Streaming tar avoids writing a temporary file, which matters when copying a tree over ssh or saving a Docker image straight into a compressor. The dash after -f is the whole trick.

What it does

Using - as the archive name with -f tells tar to read from stdin (extract/list) or write to stdout (create). This lets you chain tar into pipelines: compress on the fly, copy over a network, or feed another process without a temporary file.

Common usage

Terminal
# Copy a tree over ssh, no temp file
tar -cf - -C src . | ssh host 'tar -xf - -C /dest'
# Save a Docker image and gzip it
docker save myimage:tag | gzip > image.tar.gz
# Restore it
gunzip -c image.tar.gz | docker load

Options

FormWhat it does
-cf -Write the archive to stdout
-xf -Read the archive from stdin
tar -cf - | ...Pipe a created archive into another command
... | tar -xf -Extract an archive arriving on stdin

In CI

tar -cf - -C src . | ssh deploy@host 'tar -xpf - -C /var/www' ships a directory tree to a server in one streamed step, no intermediate artifact. Add -z on both ends to compress in transit over a slow link.

Common errors in CI

tar: Refusing to read archive contents from terminal (missing -f option?) means tar got no input and would read your terminal; you forgot -f - or the upstream command produced nothing. tar: -: Cannot write: Broken pipe means the reader on the other side of the pipe exited early; check the consumer command (often a failed ssh or a full destination disk).

Related guides

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