Operating System - HP-UX
1834140 Members
2734 Online
110064 Solutions
New Discussion

Re: adding timestamp to filename

 
so.nimda
Super Advisor

adding timestamp to filename

hi,

how do i add a timestamp to a filename?

e.g. i want to do a copy (backup) of a certain file and would like to concatenate a timestamp to it

thanks in advance !

:)
4 REPLIES 4
Rajeev  Shukla
Honored Contributor

Re: adding timestamp to filename

You can do this by touch command
touch -t < time> filename
format of time is [[CC]YY]MMDDhhmm[.SS]
Do a man on touch to find more about it.
Here is a example to change the time stamp of a file called root to May 5 2005

touch -t 200505051000 root

Cheers
Rajeev
Warren_9
Honored Contributor

Re: adding timestamp to filename

hi,

you could put the date command at the end

# cp -p source source.`date +%Y%d%m`

and it will have a file source.YYYYMMDD ...

man date for detail formatting.

GOOD LUCK!!
so.nimda
Super Advisor

Re: adding timestamp to filename

hi Rejeev & Warren,

thanks for the tip... :)

will have a go at it...

cheers !!
so.nimda
Super Advisor

Re: adding timestamp to filename

problem solved