Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a single file in a compressed tar

Tags:

linux

tar

Given a compressed archive file such as application.tar.gz which has a folder application/x/y/z.jar among others, I'd like to be able to take my most recent version of z.jar and update/refresh the archive with it.

Is there a way to do this other than something like the following?

tar -xzf application.tar.gz
cp ~/myupdatedfolder/z.jar application/x/y
tar -czf application application.tar.gz

I understand the -u switch in tar may be of use to avoid having to untar the whole thing, but I'm unsure how to use it exactly.

like image 209
Phil Avatar asked Jun 02 '10 08:06

Phil


People also ask

How would you add a file to a gzip compressed tar file?

gz file is a Tar archive compressed with Gzip. To create a tar. gz file, use the tar -czf command, followed by the archive name and files you want to add.

What command will tar and compress a file at the same time?

To extract the contents of a tar file, enter:z : Compress the tar file with gzip. j : compress the tar file with bzip2.

Is a tar file a compressed file?

The TAR file format is common in Linux and Unix systems, but only for storing data, not compressing it. TAR files are often compressed after being created, but those become TGZ files, using the TGZ, TAR. GZ, or GZ extension.


1 Answers

Well, I found the answer.

You can't use tar -u with a zipped archive. So the solution I used was the following. Note that I moved the z.jar file to a folder I created in the current directory called application/x/y for this purpose.

gzip -d application.tar.gz
tar -uf application.tar application/x/y/z.jar
gzip application.tar

When I did a tar -tf application.tar (after the update, before the gzip) it showed up properly.

like image 88
Phil Avatar answered Oct 04 '22 07:10

Phil