Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to tar a list?

 
Zhixiong Pan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic