Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 11-07-2012, 07:07 PM   #1
LQ Newbie
Registered: Feb 2004
Location: Edinburgh UK
Distribution: CentOS
Posts: 14

Rep: Reputation: 0
cp -u copies old files that already exist in the destination directory


I am using CentOS 5.8 x86_64. I have 2 hard disks, one containing the / paritition and all user files, and a 2nd one
which I use as a backup disk. I normally do a backup by using "cp -a -u" so only new files created since the last
backup need to be copied to the backup disk. I have been doing this for a number of years without any problems.
Recently, however, I noticed that the "cp -a -u" commands keeps trying to copy certain old files that already exist
on the backup disk (my cp command is aliased to "cp -i", so I get prompted whenever it tries to overwrite an existing
file). It only does this for a small number of old files, but it keeps doing it to the same old files every time I
execute "cp -a -u". I checked the time stamps of the files both on my home directory and the backup disk and they are
exactly the same (as they should be). I even tried to do a' touch' on the old files on the backup disk, so they end
up having a newer time stamp than the files on the home directory - to no avail: "cp -a -u" still tries to copy them.

Does anyone have an explanation for this strange behaviour, and how to fix it?

Thanks in advance,
Old 11-07-2012, 07:20 PM   #2
Senior Member
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,850
Blog Entries: 36

Rep: Reputation: 455Reputation: 455Reputation: 455Reputation: 455Reputation: 455
Why cp? Why not rsync? It's better for this sort of thing.

rsync -av /source /dest
Old 11-08-2012, 09:02 AM   #3
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 3,583

Rep: Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569Reputation: 1569
Are you copying to any type of FAT filesystem? Those can only represent time to a resolution of 2 seconds, so any source file with an odd-number timestamp will appear to be 1 second newer than the destination. With rsync there is a "--modify-window=" option to mask that.
Old 11-08-2012, 05:07 PM   #4
LQ Newbie
Registered: Feb 2004
Location: Edinburgh UK
Distribution: CentOS
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for your replies.

sag47: After posting my original question I discovered rsync and it works well, so in future I'll probably
use that. But this still doesn't explain the weird behaviour of 'cp -u', which as I said, only appeared
recently/ The only recent change to my set up is that I bought a new PC and re-organized my partitions
differently, but this should not have caused 'cp -u' to behave differently.

rknichols: No, I don't have any FAT filesystems, only ext2/3/4. Even if the time stamp resolution problem
also happens in ext2 filesystems, this still wouldn't explain why after doing a 'touch' on the destination
file several weeks after the original was created, the problem still recurs.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rsync deleting files from destination directory Russell P Linux - Newbie 2 07-14-2011 12:07 PM
directory listing of files that don't exist! davidhaore Linux - Software 5 10-17-2010 09:21 PM
[SOLVED] [ask]Specifying destination directory when installing Slackware ethereal1m Linux - Newbie 2 01-25-2010 05:37 AM
thunar copies directory files to usb stick out of order. curmudgeonbob Linux - General 1 07-28-2009 12:59 PM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 02:13 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:35 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration