-   Linux - Newbie (
-   -   How do I add the current date to a filename? (

sammysrefuge 03-18-2005 02:01 PM

How do I add the current date to a filename?
I am trying to set up a cron job to automatically zip my logs at the end of each day. I had someone set up a cron job for me to tar the logs but it isn't compressing the logs well enough.

What I want to be able to do is to run a command that takes a specific file and zip it into another file that includes the current date. For example: Take the file log.daily and zip it into a file (assuming that todays date is March 18, 2005)

I have tried accomplishing this a number of ways. Here is one method I have tried:

zip /usr/local/apache/logs/daily.log.'date +\%m.\%d.\%y'.zip /usr/local/apache/logs/*.daily

The end result of this command is a file named +\%m.\%d.\

The desired result again would be a file named I know this is possible, but I just don't know the correct syntax.

I would appreciate any help that you can give me.

Thanks in advance,


houdelou 03-18-2005 02:09 PM

try this :

zip /usr/local/apache/logs/daily.log.$(date +\%m.\%d.\%y').zip /usr/local/apache/logs/*.daily

the only difference is that I enclose the command between $(command) instead of 'command'

sammysrefuge 03-18-2005 02:43 PM

Works Great!

Thanks for your help.


All times are GMT -5. The time now is 09:32 PM.