15

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?

migrated from serverfault.com Jul 24 '14 at 21:42

This question came from our site for system and network administrators.

35

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

  • 2
    +1 for pointing at how to bypass an alias. Tempted to -1 for the brute force solution. – Hennes Jul 24 '14 at 21:43
  • 4
    +! for the yes pipe function - very handy! – Andrew Newby Dec 16 '16 at 8:08
13

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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