TARing multiple files at once


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TARing multiple files at once
# 1  
Old 07-09-2010
TARing multiple files at once

Hi guys, I'm trying to write a quick script to archive off some data once a week. So far I have got;

Code:
DATE=`date +%Y-%m-%d`
TARFILE=${DATE}.tar

for file in `find /usr/local/DATA/in -mtime +6`; do tar -czvf ${TARFILE} ${file}; done

The problem I have is it is going through the results of the find command and creating the same tar file for each of the results. Effectively replacing what was already added because I am using the "-c" option, so creating a new tar each time.

I guess what I need to do is create the new tar with the first result of the find command using the "-c" option and then for every other result using the "-r" which would ADD new files to an existing tar, does that make sense?

Does anyone know how I could go about doing so?

Any help would be great Smilie

Thanks!
JayC89
# 2  
Old 07-09-2010
You could redirect the find output to a file ( >> outfile ) and then hand over this file as include list for tar. So there is only 1 tar run in the end.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 07-09-2010
Never though about that! Thanks for the quick reply!! Smilie
JayC89
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep strings on multiple files and output to multiple files

Hi All, I want to use egrep on multiple files and the results should be output to multiple files. I am using the below code in my shell script(working in Ksh shell). However with this code I am not attaining the desired results. #!/bin/ksh ( a="/path/file1" b="path/file2" for file in... (4 Replies)
Discussion started by: am24
4 Replies

2. Shell Programming and Scripting

Run one script on multiple files and print out multiple files.

How can I Run one script on multiple files and print out multiple files. FOR EXAMPLE i want to run script.pl on 100 files named 1.txt ....100.txt under same directory and print out corresponding file 1.gff ....100.gff.THANKS (4 Replies)
Discussion started by: grace_shen
4 Replies

3. UNIX for Dummies Questions & Answers

Run one script on multiple files and print out multiple files.

How can I run the following command on multiple files and print out the corresponding multiple files. perl script.pl genome.gff 1.txt > 1.gff However, there are multiples files of 1.txt, from 1----100.txt Thank you so much. No duplicate posting! Continue here. (0 Replies)
Discussion started by: grace_shen
0 Replies

4. UNIX for Dummies Questions & Answers

Tar command not taring all files

I am just creating tar.gz file with comand tar -zcvf xyz.tar.gz /home/xyz/* xyz folder contains thousands of files mostly .c, .cpp, etc.. I see that many times all the files are not zipped. Many files(in hundreds) are abruptly left out. What may be the reason for this and how to resolve... (10 Replies)
Discussion started by: rupeshkp728
10 Replies

5. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

6. Shell Programming and Scripting

Taring 2 dir together

Hello everyone, I am trying to tar 2 directories together in KSH. tar -cvf temptarfile.tar scripts tar -cvf temptarfile.tar scripts.2 I need all the files in scripts and scripts.2 to be in one tar file. (1 Reply)
Discussion started by: BrutalBryan
1 Replies

7. Shell Programming and Scripting

Recursively UNTARing and then TARing back

I've just finished writing a shell script that searches for a string recursively in all text files and replace them with another string. Now, all these files come from a location nested deep within some TAR files which are inside another mother TAR. To make my script work, we had been UNTARing... (6 Replies)
Discussion started by: exchequer598
6 Replies

8. Shell Programming and Scripting

Script for Taring the all the folderand move into another server

I Need to run a Unix Aix Shell Script should contains 1)Find all the folders in the directory /fss/fin. 2)Tar the Folders. 3)Move the Tar folders into another directory /fs/fi which in server .s11003232sz.net 4)When user requests untar the Folders and move it back to the orignal... (1 Reply)
Discussion started by: sreekumar
1 Replies

9. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

10. UNIX for Dummies Questions & Answers

How to move files while Taring..

Hi, When I run the following command the files get TAR but the files in the folder remain intact. tar -cvf TARZIP.10 Nov09/ Is there any way to move them into the folder than just copying them. Thanks and regards, Gideon. (2 Replies)
Discussion started by: preethgideon
2 Replies
Login or Register to Ask a Question