Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I think the title is pretty self-explanatory. All i want is bash to warn me whenever I attempt to overwrite an existing while using cp or mv. I'd really appreciate some help. :)

share|improve this question

2 Answers 2

up vote 14 down vote accepted

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.

share|improve this answer
1  
So i guess those to commands go as aliases in my .bashrc as well. Thanks a lot. Appreciate your help. :) –  Bolt64 Jan 5 '13 at 11:33
2  
Indeed! You can append something like alias rm='rm -i' to your .bashrc or better your .bash_aliases. Read more in the post How do I create a permanent Bash alias? –  don.joey Jan 5 '13 at 11:40
1  
But i just thought of something. What about some of the scripts i've written. Will they use the aliased cp and mv or the normal one? –  Bolt64 Jan 6 '13 at 9:44

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

share|improve this answer
    
To the anonymous editor: the man page disagrees with you. –  glenn jackman Dec 24 '13 at 7:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.