View previous topic :: View next topic |
Author |
Message |
g4j Apprentice
Joined: 03 Jul 2004 Posts: 174 Location: Florida
|
Posted: Wed May 24, 2006 12:40 am Post subject: cp corrupts timestamps |
|
|
I want to use cp in a batch file to keep some local files in sync with a network file store. I've been doing this for years in Windows using the xcopy command. But I've discovered in Linux, if a file is overwritten the timestamp is changed to the current time. I need the original file time to be preserved.
How can I do this? Should I use a command other than cp?
Thanks. |
|
Back to top |
|
|
kylezhou n00b
Joined: 10 May 2005 Posts: 64 Location: Australia
|
Posted: Wed May 24, 2006 12:42 am Post subject: |
|
|
Have you tried 'cp -p'? that will preserve the timestamp _________________ You won't know the benefit of a heater unless it's cold enough. |
|
Back to top |
|
|
AllenJB Veteran
Joined: 02 Sep 2005 Posts: 1285
|
Posted: Wed May 24, 2006 9:04 am Post subject: |
|
|
You may also want to look at using rsync, which is specifically designed for what it sounds like you're doing. The cool feature of rsync over cp is that rsync will only copy over the files that have actually changed. |
|
Back to top |
|
|
g4j Apprentice
Joined: 03 Jul 2004 Posts: 174 Location: Florida
|
Posted: Wed May 24, 2006 2:45 pm Post subject: |
|
|
Thanks for the suggestions.
When I read through the man pages for cp, it sounded as though -p would not necessarly preserve the date if a file already existed in the destination. A quick test on the local file system suggests that the date is preserved even for pre-existing target files. I'll test it tonight with a remote file system.
Rsync might do the trick. When I tried it in the past, I had problems with it, but I don't remember the details. I just took another look at the man page, and I'll have to give it another try when I get home tonight. My remote file store is a network appliance and not a linux box, so it's pretty limited and might not work with the rsync protocol. |
|
Back to top |
|
|
|