Linux how to copy but not overwrite? [closed]
I want to cp
a directory but I do not want to overwrite any existing files even it they are older than the copied files. And I want to do it completely noninteractive as this will be a part of a Crontab Bash script. Any ideas?
Solution 1:
Taken from the man page:
-n, --no-clobber
do not overwrite an existing file (overrides a previous -i option)
Example:
cp -n myoldfile.txt mycopiedfile.txt
Solution 2:
Consider using rsync
.
rsync -a -v --ignore-existing src dst
As per comments rsync -a -v src dst
is not correct because it will update existing files.
Solution 3:
cp -n
Is what you want. See the man page.