1

Make cp return an error value if the target exists

view story
linux-howto

http://unix.stackexchange.com – Is there a way to make cp (from GNU coreutils on Linux) return a nonzero value in case the target file does already exist? Or is there any other small utility which is commonly available and which provides this functionality? This would be useful in shell scripts, to atomically copy a file without accidentially loosing anything, and without user interaction. A similar result can be obtained by comparing the copy against the original, but I would have hoped for a simpler solution. (HowTos)