Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TAR Command in Linux- HELP HELP

Status
Not open for further replies.

quanvu07

Technical User
Oct 23, 2010
3
0
0
US
Hi expert,

can someone help me with the command how to tar all files/directory created before jun 30 -2009?

Tar file should keep the directories intack.

I know we have to use the find command but dont know much abt the syntax.

this is what I have:
find /opt/shared/ -type f -atime +660 -exec tar cvf /dev/archive_attachments/attachments_2008.tar {} \;


Thanks

 
I don't know if you've laid out the syntax right for the find command - I have trouble with building expressions with find and grep, but I *think* I would make 2 changes to what you have listed. Keep in mind I might be full of hot air....

find /opt/shared/ -type f -atime +660 -exec > tar -cvf /dev/archive_attachments/attachments_2008.tar {} \;

I would add the > sign after the find string to tell it to direct output to the tar command, and generally (I mostly untar stuff so take this with a grain of salt) I usually have a hyphen before my tar command options. I also don't know what the extra characters at the end of the line do.

I can't hurt to try this even if I am full of hot air.... :)

 
I think that there are a couple of ways to approach this. You find syntax is essentially correct in that it executes the command given - but each time a match is made. For this reason, I think you need to vary your approach.

One would be to use the xargs command and append to your tar file each time a find is triggered. Something like this:
find /opt/shared/ -type f -atime +660 | xargs tar rvf /dev/archive_attachments/attachments_2008.tar

Another option would be to combine the finds into a temporary file and tar that.
find /opt/shared/ -type f -atime +660 > combine.lst (then)
tar -cvf /dev/archive_attachments/attachments_2008.tar -L combine.lst
 
Noway2 - should your -L be -I for the 'include file' combine.lst?

The internet - allowing those who don't know what they're talking about to have their say.
 
Oops, sorry, that should have been a -T, not a -L.
 
Ah, GNU tar of course!

The internet - allowing those who don't know what they're talking about to have their say.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top