add files to compressed tar-archive

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

add files to compressed tar-archive

Post by mister_v » Wed Jul 27, 2016 6:48 pm

Does anyone know how to add files to an existing compressed tar-file?

chris
Site Admin
Posts: 162
Joined: Mon Jul 21, 2008 9:52 am

Re: add files to compressed tar-archive

Post by chris » Wed Jul 27, 2016 8:10 pm

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: 158
Joined: Thu Mar 04, 2010 9:19 pm

Re: add files to compressed tar-archive

Post by mister_v » Fri Jul 29, 2016 12:58 pm

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

So thanks :-)

Post Reply