This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes How to tar a list? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to tar a list?" Watch "How to tar a list?" New topic
Author

How to tar a list?

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi ranchers,
I have a requirement like this: I want to tar a series log files that start from a certain time and end to a certain time. And my present approach is using "ls -lt" to display all files ordered by time and copy them one by one to another folder. After this be done, tar that folder. Is there any convenient way? Thanks.


SCJP 1.4 SCJD
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
If you don't mind writing a config file rather than a script, you could use the logrotate command in a cron job to do everything you mentioned.


Life is good on the Ponderosa,<br />but mind where you step.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

Something like this:

find mylogs -name "*.log" -newerct '7 hours ago' -and -not -newerct '3 hours ago' | xargs tar cvf logarchive.tar

However, since these are logfiles, a logrotate operation would probably be more appropriate.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to tar a list?