Copy over existing files without confirmation?

I need to copy and over-write a large amount of files, I’ve used the following command:

# cp -Rf * ../

But then whenever a file with the same name exists on the destination folder I get this question:

cp: overwrite `../ibdata1'? 

The Problem is that I have about 200 files which are going to be over-written and I don’t think that pressing Y then Enter 200 times is the right way to do it.

So, what is the right way to that?

Asked By: Itai Ganot

||

You can do yes | cp -rf myxx, Or if you do it as root – your .bashrc or .profile has an alias of cp to cp -i, most modern systems do that to root profiles.

You can temporarily bypass an alias and use the non-aliased version of a command by prefixing it with , e.g. cp whatever

Answered By: TBI Infotech

You do realise that RHEL and CentOS have tried to protect novice users by setting up aliases for the root user to prevent accidentally overwriting and deleting files?

alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'

The -i switch is what requires confirmation when modifying or removing existing files. Because alias expansion happens before execution of the command even the use of the --force -f switch will still require confirmation.

You can remove the alias permanently by editing the /root/.bashrc file, remove the alias for the duration of a session with unalias cp or for a single command use one of:

  • use the full path /bin/cp
  • use quotes "cp" or 'cp' around the command
  • use the command keyword e.g. command cp
  • escape the command cp
Answered By: HBruijn
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.