Ubuntu copy only non-existing files


Today, when trying to make a backup of one hard drive to another, I was having difficulty ensuring that only files that didnt already exist on the destination were being copied across. Thunar would ask for an action on each file and did not allow for 'perform this acction in all cases'. Nautilus did, but appeared to want to copy the entire contents again, and didnt show the filenames. Running a normal cp command did the same, would copy over the destination file if it existed. The solution is to add -u to the cp command.

This line fixes the issue:
cp /source /destination -uv
The 'u' will put it into 'update' mode which only copies the file if the source is newer or the destination doesnt already exist. The -v just makes sure to show output so you dont sit there thinking the computer is not doing anything.

No comments:

Post a Comment