Posts: 1
Joined: Wed Mar 21, 2018 1:45 am

cp command issue

Wed Mar 21, 2018 2:08 am

I am attempting to copy only the new files on one hard drive to another hard drive. I previously made a complete copy of the source drive on the destination, then added a few new files to the source drive. Then I enter the following:

cp -ruv /mnt/Drive1/* /mnt/Drive2

every time I run that command it copies everything on Drive1 to Drive2, as I understand the cp command the -u option should only copy files from the source that are newer than files with the same name on the destination.

Posts: 771
Joined: Sun Feb 12, 2017 1:46 pm
Location: Upper Hale, Surrey, UK.

Re: cp command issue

Wed Mar 21, 2018 9:49 am

If you copied all files to the other drive then added more files, it is seeing all the files on the other drive as newer than on the first drive, so is doing exactly as expected. :)

(You might like to investigate rsync, as I think it may be a more suitable solution in future.)

User avatar
Posts: 4467
Joined: Sun Jul 22, 2012 4:14 pm

Re: cp command issue

Wed Mar 21, 2018 9:54 am

You might try adding "--preserve=all" to retain timestamps. I normally use "cp -a" for these sorts of things.

Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Troubleshooting”