Linux how to copy but not overwrite?

mnowotka picture mnowotka · Feb 22, 2012 · Viewed 342.4k times · Source

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?

Answer

hovanessyan picture hovanessyan · Feb 22, 2012

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