Adding file to compressed tarfile

Hello all,

I would like to add a file to a compressed (gzip) tarfile. Normally it won't be a Problem, if I would do it in several steps. But I do not want to have unnecessary files.

So, in words:

  1. unzip the tarfile
  2. add a new file
  3. zip the tarfile

What I tried:

gzip -d < tt1.tar.gz | tar -r tt1.readme | gzip - > tt1.tar.gz
tar: /dev/rmt0: No such file or Directory

As you can see, this does not work.

Do you have any solution?

Hello API,

Could you please try following steps(not tested though) and let me know if this helps you.
1st: Extract .tar file from .tar.gz file:

gunzip filename.tar.gz

2nd: Update uncompressed .tar file with tar -u command as follows:

tar -uf filename.tar new_file

3rd: Compress the updated .tar file:

gzip filename.tar

Thanks,
R. Singh

1 Like

First off, using pipes creates temporary files - just so you know. gzip renames the output file, so no extra files when you are done.

Start with this:

gunzip tarfile.tar.gz
tar -rf tarfile.tar readme.txt
gzip tarfile.tar

then make a one-liner if you need it.

1 Like

@RavinderSingh13: That works very well. Beside of the fact that I have to use "tar -r..." instead of "-u".

@jim McNamara: Works as expected...

Thanks to all. Thats what I needed. What I did not know, was the fact, that the files do not Need more space as I have before - because they are already there...