Operating System - HP-UX
1837310 Members
2962 Online
110116 Solutions
New Discussion

Re: script question involving dates

 
SOLVED
Go to solution
John Henrikson
Regular Advisor

script question involving dates

Hello!
I know how busy everyone is.. but I've got a question that I would sure be grateful if anyone has an easy answer to..
I've got to create a script to copy a number of files everyday from one location to another..
the location of the files will change from one day to the next.. the files will always be located in a subdirectory named for the day they were created, for example, /usr/local/20080411 or 2080410, etc..
Can anyone give me some advice for how to put that in a script so that it will be incremented daily?

Many thanks for any help you can give..

John Henrikson
1 REPLY 1
Patrick Wallek
Honored Contributor
Solution

Re: script question involving dates

To get the date in the format you need you need to use:

date +%Y%m%d

This would yeild:

20080411

To use this in a script you would assign it to a variable and then use that variable in your CD command.

CURDATE=$(/usr/bin/date +%Y%m%d)
cd /usr/local/${CURDATE}

See the date man page for details on how the command above works.