1834009 Members
1770 Online
110063 Solutions
New Discussion

Re: how to find and tar?

 
SOLVED
Go to solution
Sachin_29
Advisor

how to find and tar?

Hi :
I am trying to find all the files in a directory which are 30 days old and tar .
I am doing
find $DIRNMAE -name "test.log.*" -type f -a -mtime +30 -exec tar -cvpf file.tar "{}" \;
the problem is its creating the tar for each file and so when I untar it just has the last file in it..
Is there any other way? Can I crate a 0 byte tar and use tar -uvpf? I am just not sure how to go for that.
Any suggestions?
3 REPLIES 3
Sundar_7
Honored Contributor
Solution

Re: how to find and tar?

Try this

# touch somefile
# tar -cvf file.tar somefile
# find $DIRNAME -name "test.log.*" -type f -a -mtime +30 -exec tar -rvf file.tar {} \;

I am sure there are other ways around.
Learn What to do ,How to do and more importantly When to do ?
Sachin_29
Advisor

Re: how to find and tar?

works thanks!!!
Stuart Browne
Honored Contributor

Re: how to find and tar?

As 'tar' doesn't take a file-list from stdin (like 'cpio' or other such tools), you either have to append to the tar file created (as Sundar has given an example), or provide the file-list as arguments, i.e.

# tar -cvf file.tar $(find . -type f -name "test.log.*" -mtime +30 -print)

If you expect a lot of them however, Sundar's example is much better, as this method can generate a long-list of filenames exceeding the argument list limit.
One long-haired git at your service...