1827981 Members
2473 Online
109973 Solutions
New Discussion

find and tar

 
Om prakash_1
New Member

find and tar

How can i use find with tar command. and in case i want to tar files for one particular date how can i do that. as the file names are being different.
7 REPLIES 7
Ivan Ferreira
Honored Contributor

Re: find and tar

You can use something like this:

tar cvf /dev/st0 $(find /path -mtime +30)

This will find the files older than 30 days and send it to tape. You can play with the find command as you want.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Hemmetter
Esteemed Contributor

Re: find and tar

Hi

try
# touch -t 0703200000 starttimefile
# touch -t 0703220000 stoptimefile

# tar cvf arc.tar $(find /path -type f \( -newer starttimefile -a ! -newer stoptimefile \) )


#if you have lots of files you may try:

#find /path -type f \( -newer starttimefile -a ! -newer stoptimefile \) | xargs tar rvf arc.tar

rgds
HGH

Om prakash_1
New Member

Re: find and tar

when i use
find tmp -type f -exec grep "tmp" {}\;

i get the this error.

find: missing argument to `-exec'
Om prakash_1
New Member

Re: find and tar

well this works greatly... but i was wondering how can i specify a date for eg. if i want to archive all the files which were created on say Feb 23. like using mtime or something like that.
Ivan Ferreira
Honored Contributor

Re: find and tar

Yes, as described in the Hemmetter solution, you can create a file with a "baseline date" with the touch command, and use that file as reference for your search.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Stuart Browne
Honored Contributor

Re: find and tar

The method I'd use (instead of xargs) is to:

find . | tar Tcvf - file.tar

The 'T' coupled with '-' takes the file-list from STDIN. This allows a more dynamic method (and not limited to command-line size) of creating an arcive.

That, or use 'cpio'.. ;)
One long-haired git at your service...
Mike Stroyan
Honored Contributor

Re: find and tar

You should have a look at the pax command.
It can read and write tar format.
But it is also very good at filtering which files will be written based on file names and modification times.

pax -w -T 02230000,02240000 /tmp > tmp.tar