Copy without overwriting
Copy without overwriting an existing file with cp -n. In GNU coreutils 9.1 it skips the copy and still exits 0, a status that later releases changed.
A copy should leave files in the destination alone when they are already there, so a rerun cannot destroy changes.
mkdir -p src dst
echo new > src/a.txt
echo keep > dst/a.txt
cp -n src/a.txt dst/
echo "exit status: $?"
cat dst/a.txtexit status: 0
keep-n is --no-clobber in GNU cp. The existing file wins and the command reports success, so a repeated run cannot overwrite local edits. The alternative, -i, stops to ask, which does not suit a script.
The exit status of a skipped copy has changed between coreutils releases, and the status of 0 shown here is from coreutils 9.1 on Debian 12, so check the release notes of the version you deploy before testing $? in a script. For a guarantee of what was copied, rsync --ignore-existing is the clearer tool.