Adding file to compressed tarfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding file to compressed tarfile
# 1  
Old 10-11-2016
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:

Code:
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?
# 2  
Old 10-11-2016
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:
Code:
gunzip filename.tar.gz

2nd: Update uncompressed .tar file with tar -u command as follows:
Code:
tar -uf filename.tar new_file

3rd: Compress the updated .tar file:
Code:
gzip filename.tar

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-11-2016
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:
Code:
gunzip tarfile.tar.gz
tar -rf tarfile.tar readme.txt
gzip tarfile.tar

then make a one-liner if you need it.
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 10-11-2016
@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...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Size of compressed file

Hi All, Is there is any way to find the size of compressed file without doing decompression. The size should give the original uncompressed data size Thanks Arun (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. Solaris

Command in Solaris 10 to exlude more than one directory while creatinga tarfile

Hi, I am using solaris 10.Could anyone please help me on command to create a tar file by excluding more than one directory.I have tried below command but it did not work. tar -pcvf orderm_setup.tar . --exclude=/orderm/common/7.0/logs001 Advance thanks for your reply. (2 Replies)
Discussion started by: muraliinfy04
2 Replies

3. Shell Programming and Scripting

Get Compressed byte offset from .gz file

Hi , I have a .gz file whose contents look like below. data1^filename1 data2^filename2. .. . . Is it possible to find out the byte offset of each record from the .gz file. Like in an uncompressed file. grep -nb "Filename" give the byte offset of the record in this case. ... (4 Replies)
Discussion started by: chetan.c
4 Replies

4. Shell Programming and Scripting

compressed file

i have a file 4d7a94d0.bbb.1292 when i do file 4d7a94d0.bbb.1292 the ouput is below 4d7a94d0.bbb.1292: gzip compressed data - deflate method and i run this command gunzip -c 4d7a94d0.bbb.1292 | awk '{gsub("\"","")}/I_ACCOUNT_ID/{print $2}' RS=":|;" FS="," i get... (3 Replies)
Discussion started by: blackzinga80
3 Replies

5. Shell Programming and Scripting

Process a compressed file

Hi i have a filename.tar.bz2 and i have to parse it with a tool that doesn't support compressed files. I have to do it for many big files, so i can't decompress and then process. I'd like to do something like: tar -jxvf namefile.tar.bz2 | parsing_tool i mean analyze it directly,... (4 Replies)
Discussion started by: Dedalus
4 Replies

6. UNIX for Dummies Questions & Answers

compressed file

I compressed a file by using gzip command gzip <<xx>> filename changed to xx.gz How to view this xx.gz file. Any idea. Thanks in advance. (7 Replies)
Discussion started by: venkatesht
7 Replies

7. Shell Programming and Scripting

check to see if a file is compressed before trying to compress

I simply need to compress all files in a directory that are not already compressed and that are older than 10 days? I have this so far. I need to add to this so I don't try and compress file that are already compressed. Or if you think this can be simplified let me know. Thx. find... (3 Replies)
Discussion started by: rstone
3 Replies

8. UNIX for Advanced & Expert Users

Is it possible to see the content of the compressed file?

How we can view the content of the file,if it compressed (or) Zipped ,without uncompress ? I have one file ,i compressed it,without uncompressing the file.Is it possible to see the content of the file? (2 Replies)
Discussion started by: bobprabhu
2 Replies

9. Shell Programming and Scripting

Check if file compressed or not

Is there a way I can check if a file is comppressed or not? (Be it tar/gzip or compress). trying to write a generic housekeeping scrit that will delete files over 6 months old and compress any uncompressed files if less than 6 months old. But not sure if there is a clever way to check except for... (4 Replies)
Discussion started by: badg3r
4 Replies

10. UNIX for Dummies Questions & Answers

renaming a compressed file to filename without .Z

In a shell script I would like to use a compressed file name, i.e. with suffix of .Z, as a file input $1. After the file in uncompressed, I would like to use the file name without the .Z . How do I do this? Thank you. (8 Replies)
Discussion started by: bruceps
8 Replies
Login or Register to Ask a Question