Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
cp corrupts timestamps
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
g4j
Apprentice
Apprentice


Joined: 03 Jul 2004
Posts: 174
Location: Florida

PostPosted: Wed May 24, 2006 12:40 am    Post subject: cp corrupts timestamps Reply with quote

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
View user's profile Send private message
kylezhou
n00b
n00b


Joined: 10 May 2005
Posts: 64
Location: Australia

PostPosted: Wed May 24, 2006 12:42 am    Post subject: Reply with quote

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
View user's profile Send private message
AllenJB
Veteran
Veteran


Joined: 02 Sep 2005
Posts: 1285

PostPosted: Wed May 24, 2006 9:04 am    Post subject: Reply with quote

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
View user's profile Send private message
g4j
Apprentice
Apprentice


Joined: 03 Jul 2004
Posts: 174
Location: Florida

PostPosted: Wed May 24, 2006 2:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum