sorry .. totally different subject Help in Unix.

johnkumar

Registered Users (C)
Need some help.

In Unix, I need to "tar" directories/sub-directories and also filter the files within these directories/sub-directories, say *.dat (dat files only).

Thank you.
 
find . -name '*.dat' -print | xargs tar -cvf tarfile.tar

do a man on "find" and "tar" for more help.

Good luck
 
Originally posted by johnkumar
Need some help.

In Unix, I need to "tar" directories/sub-directories and also filter the files within these directories/sub-directories, say *.dat (dat files only).

Thank you.
tar cvf xxx.tar `find yyy -name '*.dat' -print`
 
Thanks for your Help.

Option 1.
This Command ran successfully but for some reason It did not pick all the files
find . -name '*3011894*' -print | xargs tar -cvf tarfile.tar


Option 3
This command give be error...
tar -cvf tarfile.tar 'find . -name '*3011894*' -print'

tar: find . -name *3011894* -print: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Thanks for your Help.
 
The reason why the proposed solutions don't work is very simple - the command line length gets in the way. Basically, xargs fails to group all the input file names within a single command line. Which is OK, by the way.

One thing you may want to try is to update the archive instead of creating it, like this:

find . -name '*.dat' -print | xargs tar uf tarfile.tar

If your specific version of tar does not support updating an inexistent archive, or you don't delete or move the target archive after processing, you may want to prepend the command line above with this:

tar cf tarfile.tar

The command line above will create an empty archive without any objects in it -- just a header, really. So, the whole command line would look like the following:

tar cf tarfile.tar; find . -name '*.dat' -print | xargs tar uf tarfile.tar

Also you may want to explore vendor-specific command line parameters for your tar. Some vendors provide means to get a list of objects for archiving from an external file (e.g. -L for AIX tar). But it won't be portable and using those options is rather cumbersome.
 
I'd

I'd make another directories and copy all the *.dat files over to the new directory. eg. dat_files

Then, from the 'dat_files' directory, I bundle the entire directory up into a single file ("find dat_files -print | gcpio -ocB -F dat_files.04212004"). The advantage to this instead of sending individual binaries is that when you expand this file out, the binaries will keep their original permissions.


Then to reopen the directory I'd use
'gcpio -icB -F <filename>' .

Or you may copy this directory (under which you'd have subdirectories) to some other name and use rm command to get rid of all the other directories...


Cheers!
Currys
 
Re: Thanks for your Help.

for option #3:

tar -cvf tarfile.tar `find . -name '*3011894*' -print`

note the first and last quote is really the one found below the ~ button. The inner one is a regular quote ' *3011894* '.

` <execurtes a command > `



Originally posted by johnkumar
Option 1.
This Command ran successfully but for some reason It did not pick all the files
find . -name '*3011894*' -print | xargs tar -cvf tarfile.tar


Option 3
This command give be error...
tar -cvf tarfile.tar 'find . -name '*3011894*' -print'

tar: find . -name *3011894* -print: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Thanks for your Help.
 
Top