cp -u copies old files that already exist in the destination directory
Linux - GeneralThis 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.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cp -u copies old files that already exist in the destination directory
Hi,
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.