Ask Dave Taylor: Tech and Business

Wednesday

How do I rotate files in Unix?

On Solaris I have cron job which creates some log files and it puts it under a directory, this directory name is created based on system date for example directory name are like 08162005, 08172005 so on..

What I need is I want to do a rotation for these log directories every 14 days since these are directories with system dates, I am having little trouble getting this done,

Is there any way you can solve this for me??


If you're trying to figure out how to do date math, then this is going to seem like a very difficult task. But, in fact, what you're talking about is a perfect job for one of the Swiss Army Knives of the Unix command line: find.

Specifically, find has a flag -ctime which lets you test how long ago the file was created. The notation that the program uses for specifying dates is a bit confusing, but I'll give you a shortcut...