Append files to a existing tar file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append files to a existing tar file.
# 1  
Old 07-16-2011
Append files to a existing tar file.

Hi all,

I want to check whether tar file exists in the directory or not. If tar file exists in the directory then I want to append the files to it.

I am using the below command to tar files if the file does not exist.

tar zcvf <tar file name> <Files to append>

However, if want to append some more files to the existing tar file with above command, files in the tar are getting deleted.

I tried using the below command but I am getting error as below.
"tar: You may not specify more than one `-Acdtrux' option"

tar zcvfr <tar file name> <additional files to append>

Request you to provide the code for file check and tar command if tar file exists.

Thanking you in advance.
Nagaraja Akkivalli.





Thanks and Regards
Nagaraja Akkivalli.

Last edited by Nagaraja Akkiva; 07-21-2011 at 01:43 PM..
# 2  
Old 07-16-2011
I'd think you want 'u' (update existing) instead of 'c' (create new) in your flags for tar.

As a little aside, you may also want to drop the z flag and pass the tar through a compression program of your choice - that way it'll work with non-gnu versions of tar and/or opens up the option to use better compression like bzip.
This User Gave Thanks to Smiling Dragon For This Post:
# 3  
Old 07-16-2011
Thanks Smiling Dragon for you response..!!

Let me explain it clearly....

Say, tar ABC.tgz has a.dat, b.dat and c.dat in it. If I want to add one more file(d.dat) to it then tar should not overide the existing file content. After taring 4th file then it should have all 4 (a.dat, b.dat and c.dat, d.dat) files.

Can I assume "update existing" does the same as I explained above?

Can you plz share the piece of code if you have or can you point to link where I can get this?

Thanks and Regards
Nagaraja Akkivalli
# 4  
Old 07-17-2011
One more update.

I used below command if tar file existing.
Code:
tar rvf <tar file name> <additional files to append> , 

tar command was successful but when I untarred it, tar had only one file which was tarred first.

Please see the below code.
Code:
[user@dbname processed 04:31:05 AM]$tar zcvf FileName122011.tgz FileName_20110325101.dat
FileName_20110325101.dat
[user@dbname processed 04:31:05 AM]$tar rvf FileName122011.tgz FileName_20110325102.dat
FileName_20110325102.dat
[user@dbname processed 04:31:05 AM]$ls -ltr For*
-rwxrwSrwt 1 root root 402 Jul 16 02:48 FileName_20110519054238_0.dat
-rwxrwSrwt 1 root root 402 Jul 16 02:48 FileName_20110519053824_0.dat
-rwxrwSrwt 1 root root 415 Jul 16 02:48 FileName_20110519EP_vaL_2.dat
-rwxrwSrwt 1 root root 608 Jul 16 02:48 FileName_20110602031917_0.dat
-rwxrw-r-x 1 root root 416 Jul 17 11:42 FileName_20110325101.dat
-rwxrwSr-t 1 root root 416 Jul 17 11:51 FileName_20110325102.dat
-rwxrwxrwx 1 root root 10618 Jul 17 11:53 FileName122011.tgz
[user@dbname processed 04:31:05 AM]$rm -rf FileName_20110325102.dat
[user@dbname processed 04:31:05 AM]$rm -rf FileName_20110325101.dat
[user@dbname processed 04:31:05 AM]$ls -ltr For*
-rwxrwSrwt 1 root root 402 Jul 16 02:48 FileName_20110519054238_0.dat
-rwxrwSrwt 1 root root 402 Jul 16 02:48 FileName_20110519053824_0.dat
-rwxrwSrwt 1 root root 415 Jul 16 02:48 FileName_20110519EP_vaL_2.dat
-rwxrwSrwt 1 root root 608 Jul 16 02:48 FileName_20110602031917_0.dat
-rwxrwxrwx 1 root root 10618 Jul 17 11:53 FileName122011.tgz
[user@dbname processed 04:31:05 AM]$tar zxvf FileName122011.tgz
FileName_20110325101.dat
gzip: stdin: decompression OK, trailing garbage ignored
tar: FileName_20110325101.dat: Cannot utime: Operation not permitted
tar: Child returned status 2
tar: Error exit delayed from previous errors


Last edited by Franklin52; 07-17-2011 at 02:14 PM.. Reason: Please use code tags for data and code samples, thank you
# 5  
Old 07-21-2011
This is how I did it.

If tar file does not exists use below command.
tar -cvf <tar-file-name.tar> < files to be added>

If tar file exists then use.
tar -rf <tar-file-name.tar> < files to be append>

Thanks
Nagaraja
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append files (backup .tar)

Hi all, I have to write a script which will keep for a particular user (username is first argument) backups of the account area to another. The script should accept as the second argument is a directory (or file), create one by storing a copy of the argument (using tar) and copies it to the list... (0 Replies)
Discussion started by: peter20
0 Replies

2. Shell Programming and Scripting

Matching column then append to existing File as new column

Good evening I have the below requirements, as I am not an experts in Linux/Unix and am looking for your ideas how I can do this. I have file called file1 and file2. I need to get the second column which is text1_random_alphabets and find that in file 2, if it's exists then print the 3rd... (4 Replies)
Discussion started by: mychbears
4 Replies

3. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

4. Shell Programming and Scripting

Append to existing line

I have a file which has lines that end with a plus (+) sign. I would like to get the next line appended to the one with the plus. For example bla bla bla bla bla + blip blip blip would become bla bla bla bla bla blip blip blip However not all lines end with a plus sign . I would... (2 Replies)
Discussion started by: bombcan
2 Replies

5. Shell Programming and Scripting

append existing file with zeroes bsed on position

Hi i am trying to append value with 0 to an existing file in the position 50-56 & 58-64 only where empty space is there Rule: 1 row already has some value and i do not want to change anything for this row. 2nd record below you see the position 50-64 is empty, i want to replace with 0000000... (3 Replies)
Discussion started by: kshuser
3 Replies

6. Shell Programming and Scripting

Adding file to an existing tar

Hi Friends, I want to know the command to add a new file in a existing tar file. For Ex: I have a tar file file1.tar with the contents one.txt two.txt three.txt Now I need to add file four.txt to this existing tar file, how can I do it? Thanks in advance (4 Replies)
Discussion started by: mr_manii
4 Replies

7. UNIX for Dummies Questions & Answers

how to add files to an existing tar file - HP-UNIX

Hello, What is the command to add files to an existing tar file. Thanks, (5 Replies)
Discussion started by: Nomaad
5 Replies

8. AIX

append file with tar command

hello, can i append files into tape without clear this tape thanks for help (3 Replies)
Discussion started by: mbakry23
3 Replies

9. UNIX for Advanced & Expert Users

Shell script to append a time for the existing error log file

Hi Guys, the requirement is like this, i am having a error log file in this format, 4594.493: parallel nursery GC 2594592K->2544691K (2969600K), 30.848 ms 4605.958: parallel nursery GC 2634887K->2584986K (2969600K), 38.900 ms 4619.079: parallel nursery GC 2822555K->2774812K... (12 Replies)
Discussion started by: gsprasanna
12 Replies

10. UNIX for Dummies Questions & Answers

delete a file from an existing Solaris tar

How can I delete a file from an existing Solaris tar file ? (not gtar) (2 Replies)
Discussion started by: avnerht
2 Replies
Login or Register to Ask a Question