tar -f: Naming the Archive File (Usage & CI Errors)
tar -f names the archive file, or uses a dash for the pipe.
The -f flag is where most tar typos live: forget it and tar talks to the tape device, or put a flag between -f and its filename and tar grabs the wrong argument.
What it does
tar -f <file> sets the archive path for create, extract, and list. Use -f - to read from stdin or write to stdout for pipelines. Without -f, classic tar defaults to the TAPE environment variable or a built-in device, which is almost never what you want on a CI runner.
Common usage
tar -cf out.tar dir/ # -f then filename
tar -xf in.tar.gz
tar -cf - dir/ | gzip > out.tar.gz # write to stdout
gzip -dc in.tar.gz | tar -xf - # read from stdinOptions
| Form | What it does |
|---|---|
| -f <file> | Read/write the named archive file |
| -f - | Use stdin (extract/list) or stdout (create) |
| -cf / -xf / -tf | Bundled clusters: the filename follows -f |
| (no -f) | Falls back to the default tape device or $TAPE |
Common errors in CI
When -f is missing, GNU tar prints tar: -: Cannot write: Broken pipe or tar: Refusing to read archive contents from terminal (missing -f option?). In a bundled cluster the filename must follow -f, so tar -cf -z out.tar dir is wrong: tar reads -z as the filename. Write -czf out.tar.gz dir or keep -f last.