Page 1 of 1

add files to compressed tar-archive

Posted: Wed Jul 27, 2016 6:48 pm
by mister_v
Does anyone know how to add files to an existing compressed tar-file?

Re: add files to compressed tar-archive

Posted: Wed Jul 27, 2016 8:10 pm
by chris
Short answer you can't:

Code: Select all

tar: Cannot update compressed archives
You can however update/add files to normal tar-files.

Code: Select all

tar -uvf file.tar addfile.pdf
So there are 2 options.
you can extract everything from the compressed tar-file
and then re-add everything, including the new file.

Or, and perhaps better.
first compress the file and then add to the tar-archive.

Code: Select all

gzip -c $FILE > $COMPRESSED.gz;
tar -uvf $NEWARCHIVE $COMPRESSED.gz;

Re: add files to compressed tar-archive

Posted: Fri Jul 29, 2016 12:58 pm
by mister_v
Not really what I was looking for,
but it works.

So thanks :-)