tar -r and -u: Append and Update (CI Errors)
tar -r appends new members and -u updates ones that changed.
Append and update let you add to an existing archive without rebuilding it, but they only work on uncompressed tar files, which trips up a lot of CI scripts.
What it does
tar -r (--append) adds the named files to the end of an existing archive. tar -u (--update) appends only files that are newer than the copy already in the archive. Both require a plain, uncompressed .tar, because tar cannot seek to the end of a gzip or zstd stream to append.
Common usage
tar -rf archive.tar newfile.txt # append a file
tar -rf archive.tar -C build extra/ # append from another dir
tar -uf archive.tar src/ # add only changed filesOptions
| Flag | What it does |
|---|---|
| -r / --append | Add files to the end of an archive |
| -u / --update | Append only files newer than the stored copy |
| -f <file> | The .tar to modify (must be uncompressed) |
| (note) | Update never deletes; old versions stay in the archive |
Common errors in CI
tar: Cannot update compressed archives means you tried -r or -u on a .tar.gz; decompress first, append, then recompress, or rebuild the archive in one tar -c pass. Remember that -u does not replace members: it appends newer copies, so the archive can grow and extraction uses the last copy written.