Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to force cp to overwrite without confirmation

I'm attempting to utilize the cp command and power an overwrite.

I have attempted cp - rf/foo/*/bar, yet I am as yet provoked to affirm each overwrite.
by

2 Answers

ninja01
This is probably caused by cp being already aliased to something like cp -i. Calling cp directly should work:

/bin/cp -rf /zzz/zzz/ /xxx/xxx

Another way to get around this is to use the yes command:

yes | cp -rf /zzz/zzz/
/xxx/xxx
RoliMishra
You probably have an alias somewhere, mapping cp to cp -i; because with the default settings, cp won't ask to overwrite. Check your .bashrc, your .profile etc.

See cp manpage: Only when -i parameter is specified will cp actually prompt before overwriting.

You can check this via the alias command:

$ alias
alias cp='cp -i'
alias diff='diff -u'
....


To undefine the alias, use:

$ unalias cp

Login / Signup to Answer the Question.