retain create/mod date and time of files

Hi,

I have a requirement by which I need to take a snapshot of a certain directory of a certain types of files into a target directory within the same server (HP-UX 9000).
The problem is that the files created in the target directory has the date and time of when the files were copied over.
How do I maintain the date and time the files were modified/created in the source directory. Is there any commands/utilities that will enable this preservation. Anys suggestions/ideas are greatly appreciated. thanks.

Jerardfjay

I don't know about hpux, but gnu cp has the -a option that does what you want.
Generally tar is available though, so you could do something like

(cd src/dir && tar c -p .) | (cd dst/dir && tar x -p)

You can search for more tar examples at http://www.pixelbeat.org/cmdline.html

hi

I guess you can use "find" command with -newer or -mtime option for getting those files. refer man pages for detailes about this command.

as far as I know --- the copy utilities generally have a "preserve" option to preserve file attributes ... do a man lookup on cp, tar, cpio, etc. ...

cp -p sourcefile newfile
tar cfp - source | (cd $destdir; tar xfp -)

Yes it's just the -a option. That preserves ALL attributes. Permissions, ownership, creation time, modification time etc etc etc....

It's what you use for backups :wink:

thank you all for your input. I shall use one of the above. :slight_smile: