Well, it doesn't work, because it is compressed.
Code:
$ tar czf test.tgz 1.txt 2.txt
$ tar rzf test.tgz 3.txt 4.txt
tar: Cannot update compressed archives
This doesn't work either:
Code:
$ tar czvf test.tgz 1.txt 2.txt
$ tar czvf - 3.txt 4.txt >>test.tgz
$ tar tzf test.tgz # shows only 1.txt and 2.txt
The reason is the end-of-archive marker written by the first tar (meaning: 1024 byte binary zero [edit: it is 'two blocks' actually, e.g. 2*4096 byte]).
So the next question is: how to prevent tar from writing such marker.
I am going to check the source of tar, then keep blogging.
Comments are welcome.
PS: gunzip + append + gzip sequence isn't a solution, it would be a waste of resoures.
Edit: astrogeek suggested using option
-i at untar-time. (Thank you, astrogeek.) It does work:
Code:
$ tar -i -tzf test.tgz # shows all four files
Problem is, the unlucky guy who will have to use these files might be someone else in the future when I'm long dead. So it would be better if he shouldn't be using any extra options at untar-time.
Edit: it is create.c:write_eot in tar-source. It is called unconditionally. (At least in non-incremental mode. I don't know what incremental mode is, and don't wish to know.) Next idea is creating some tar-replacement (actually, I've done that on platform BS2000 some decades before), or using dd(1) to remove the last 1024 bytes of archive (which is not
guaranteed to be 1024, it might be less or more...)
Edit: now this "works":
Code:
$ tar cf - 1.txt 2.txt | head -c -8192 | gzip >test.tgz
$ tar cf - 3.txt 4.txt | head -c -8192 | gzip >>test.tgz
Okay, but where this 8192 comes from? How platform-independent it is? Clearly it isn't a
solution, it is a
hack.
Edit: Rather:
Code:
$ tar -b 1 -cf - 1.txt 2.txt | head -c -1024 | gzip >test.tgz
$ tar -b 1 -cf - 3.txt 4.txt | head -c -1024 | gzip >>test.tgz