tar -c: Create an Archive (Usage & CI Errors)
tar -c packs files and directories into one archive stream or file.
Creating archives is the first half of every cache and artifact step. The flags decide what goes in and where the archive lands.
What it does
tar -c (create) reads the named files and directories and writes them into a single archive. On its own tar writes to standard output; pair it with -f to name an output file. Directories are added recursively by default.
Common usage
tar -cf archive.tar dir/
tar -cvf archive.tar file1 file2 dir/ # verbose: list members
tar -czf archive.tar.gz dir/ # gzip-compressed
tar -cf - dir/ | ssh host 'cat > backup.tar' # to stdout, pipedOptions
| Flag | What it does |
|---|---|
| -c / --create | Create a new archive |
| -f <file> | Write to <file> instead of stdout (use - for stdout) |
| -v / --verbose | List each file as it is processed |
| -z / --gzip | Filter the archive through gzip |
| -C <dir> | Change to <dir> before adding the following paths |
In CI
Packaging build output as an artifact is a tar -c step: tar -czf dist.tar.gz -C build . creates a gzip archive of the build/ contents without the leading build/ prefix. Upload that single file, then extract it on the consumer job.
Common errors in CI
tar: dir: Cannot stat: No such file or directory followed by tar: Exiting with failure status due to previous errors means a path you listed does not exist relative to the current directory. tar still creates the archive from the parts it could read but exits non-zero, failing the job. Check the working directory and use -C to anchor paths.