I'm trying to use the cp
command and force an overwrite.
I have tried cp -rf /foo/* /bar
, but I am still prompted to confirm each overwrite.
You can do yes | cp -rf xxx yyy
, but my gutfeeling says that if you do it as root - your .bashrc
or .profile
has an alias of cp
to cp -i
, most modern systems (primarily RH-derivatives) do that to root profiles.
You can check existing aliases by running alias
at the command prompt, or which cp
to check aliases only for cp
.
If you do have an alias defined, running unalias cp
will abolish that for the current session, otherwise you can just remove it from your shell profile.
You can temporarily bypass an alias and use the non-aliased version of a command by prefixing it with \
, e.g. \cp whatever
As some of the other answers have stated, you probably use an alias somewhere which maps cp
to cp -i
or something similar. You can run a command without any aliases by preceding it with a backslash. In your case, try
\cp -r /zzz/zzz/* /xxx/xxx
The backslash will temporarily disable any aliases you have called cp
.
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
By default cp
has aliase to cp -i
. You can check it, type alias
and you can see some like:
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
To solve this problem just use /bin/cp /from /to
command instead cp /from /to
So I run into this a lot because I keep cp aliased to cp -iv
, and I found a neat trick. It turns out that while -i
and -n
both cancel previous overwrite directives, -f
does not. However, if you use -nf
it adds the ability to clear the -i
. So:
cp -f /foo/* /bar <-- Prompt
cp -nf /foo/* /bar <-- No Prompt
Pretty neat huh? /necropost