How do I make bash warn me when overwriting an existing file?

Solution 1:

You should use the interactive mode which makes sure you get a 'prompt before overwrite'

cp --interactive
mv --interactive

Or in short

cp -i
mv -i

Type man cp or man mv on your command line to find out more.

Solution 2:

You also want to put set -o noclobber in your .bashrc. This will raise an error if you try to overwrite an existing file by output redirection.

$ set -o noclobber
$ echo one > afile
$ echo two > afile
bash: afile: cannot overwrite existing file

You can force the redirection to work with special syntax:

$ echo two >| afile
$ cat afile
two

http://www.gnu.org/software/bash/manual/bashref.html#Redirecting-Output