add files to compressed tar-archive

Bash shell is the common linux command language.
Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

add files to compressed tar-archive

Post by mister_v »

Does anyone know how to add files to an existing compressed tar-file?
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: add files to compressed tar-archive

Post 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;
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Re: add files to compressed tar-archive

Post by mister_v »

Not really what I was looking for,
but it works.

So thanks :-)
Post Reply