find and tar 700 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find and tar 700 files
# 1  
Old 12-17-2008
find and tar 700 files

i have some 700 files of the same pattern differing only in their datestamp. below some of the files.

Quote:
CurrentCollectorMeterReadBackup_20080016020014881
CurrentCollectorMeterReadBackup_20080016040052637
CurrentCollectorMeterReadBackup_20080016050001787
CurrentCollectorMeterReadBackup_20080016050059673
CurrentCollectorMeterReadBackup_20080017150008681
i want to tar them all into one tar file.but the below normal command is telling me "arg list too long"
Code:
tar -cvf Archive1.tar CurrentCollectorMeterReadBackup*

also i tried the below command but not getting it tarred
Code:
find . -type f -name "CurrentCollectorMeterReadBackup*" | xargs tar rvf myfile.tar

i think we can tar this 700 files using find command, can anyone help me out.?

Last edited by ali560045; 12-17-2008 at 03:04 AM..
# 2  
Old 12-17-2008
Quote:
Originally Posted by ali560045
also i tried the below command but not getting it tarred
Code:
find . -type f -name "CurrentCollectorMeterReadBackup*" | xargs tar rvf myfile.tar

I don't see anything wrong with this command.
Are you getting any error?
Rather did you check myfile.tar, with tvf option?
# 3  
Old 12-17-2008
the problem is that when i execute that command it tells

myfile.tar: does not exists
# 4  
Old 12-17-2008
am using GNU version of tar and above command is working fine for me.
I am not sure if your version expect myfile.tar since r is present in the tar option. Please try following line (Changed r to c)
Code:
find . -type f -name "CurrentCollectorMeterReadBackup*" | xargs tar cvf myfile.tar

# 5  
Old 12-17-2008
when i use cvf it only tar 193 files instead of 700 files, so i m thought using rvf.

The below comman tar only 193 files instead of 700 files
Code:
find . -type f -name "CurrentCollectorMeterReadBackup*" | xargs tar -cvf `myfile.tar`

Using rvf i m getting error
Code:
find . -type f -name "CurrentCollectorMeterReadBackup*" | xargs tar -rvf `myfile.tar`

error:

ksh: myfile.tar: not found
tar: directory checksum error (0 != 42256)
tar: directory checksum error (0 != 42298)

Last edited by ali560045; 12-17-2008 at 03:58 AM..
# 6  
Old 12-17-2008
please can someone help em out ?

Thanks in advance
# 7  
Old 12-17-2008
i think it's better to make a directory, then move these files into it and archive the directory.
Code:
step1, 
mkdir x
step 2,
find . -name "your-pattern" -exec mv {} x \;
step 3,
tar cf x.tar x

or you can use loop. when dealing with first file(s) you can use tar cvf to generate a tar-ball file,
the remainds you can use tar rvf to add them into archive file one by one.
the following is a demo:
Code:
find . -name "your-pattern" -type f |
(
i=0
while read x; do
  if [ $i -eq 0 ]; then
    echo tar cf x.tar $x
  else
    echo tar rf x.tar $x
  fi
  ((i+=1))
done
)
## but this version maybe runs very slowly. 
you may use xargs to improve it. that maybe looks like
find . -name "your-pattern" -type f |
xargs -n50 |
(
.... ## the same as listed above
)
# so can reduce loop times


Last edited by ivhb; 12-17-2008 at 11:26 AM..
This User Gave Thanks to ivhb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unable to run files with 700-777 permissions

I finally installed Chakra Linux and noticed whether I create or extract a file with 700, 755, 775 permissions a * sign is listed at the end of the filename: $ ls -l bin/32 total 16440 -rwxr-xr-x 1 501 utmp 6321496 09.12.2013 04:02 bitcoind* -rwxr-xr-x 1 501 utmp 10508613 09.12.2013 04:02... (10 Replies)
Discussion started by: Azrael
10 Replies

2. UNIX for Dummies Questions & Answers

Files count mismatch when used with Tar with find

Hi I have used the below steps and found some discrepancies step 1 : find ./ -type f -mtime +7 -name "*.00*" | wc -l = 13519 ( total files ) ( the size of this files is appx : 10GB ) step 2: find ./ -type f -mtime +7 -name "*.00*" | xargs tar zcvf Archieve_7.tar.gz step... (7 Replies)
Discussion started by: rakeshkumar
7 Replies

3. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

4. Shell Programming and Scripting

Find *.tar files under all subdirectories

Hi there, I'm new to shell scripting... I've a situation like to find *.tar files under all subdirectories in "/home/abcd" and i used the below, find /opt/lhapp ! -name "temp" | more the above works fine.. Now don't need search few direcotries like "/home/abcd/aaaa",... (15 Replies)
Discussion started by: skcvasanth
15 Replies

5. Shell Programming and Scripting

find files older than and containing then tar.

I'm tring to: find files recursively older than x days that contain dat or DAT then tar them I can find the files older than 90 days containing dat with this: find . -mtime +90 -type f -name "*dat*" -exec tar -cvvfp /some/path/some.tar {} \; but how do I do it case insensitive? ... (3 Replies)
Discussion started by: Ikon
3 Replies

6. Shell Programming and Scripting

Find most recent files in dirs and tar them up?

Hey all.. This should be simple but stoopid here can't get head around it! I have many directories, say 100 each with many files inside. I need a script to traverse through the dirs, find most recent file in each dir and add it to a tar file. I can find the files with something like for... (1 Reply)
Discussion started by: bobdung
1 Replies

7. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

8. Solaris

Find files older than x days and create a consolidated single tar file.

Hello, I need help in finding files older than x days and creating a single consolidated tar file combining them. Can anyone please provide me a script? Thanks, Dawn (3 Replies)
Discussion started by: Dawn Bosch
3 Replies

9. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

10. UNIX for Dummies Questions & Answers

find a data from several .tar,.gz files

Hi I have a several files with .tar or .gz in a known location. i have files with one of the several files of .tar or .gz text.txt help.pl move.txt how do i write a script to find out those particular files .tar or .gz where that contains the above mentioned files (i.e,... (2 Replies)
Discussion started by: gkrishnag
2 Replies
Login or Register to Ask a Question