23

Does anyone know how I would turn off the interactive mode when using cp?

I am trying to copy a directory recursively into another and for each file that is getting overwritten I have to answer 'y'.

The command I am using is:

cp -r /usr/share/drupal-update/* /usr/share/drupal

But I get asked to confirm each overwrite:

cp: overwrite `./CHANGELOG.txt'? y  
cp: overwrite `./COPYRIGHT.txt'? y  
cp: overwrite `./INSTALL.mysql.txt'? y  
cp: overwrite `./INSTALL.pgsql.txt'? y  
...

I am using ubuntu server version jaunty.
Thanks!

Zoredache
  • 128,755
  • 40
  • 271
  • 413
Faisal Vali
  • 333
  • 1
  • 2
  • 7
  • 1
    Removing the alias is typically "unalias". It is also a bad idea to change the question, as the answers no longer makes sense. – pehrs Mar 06 '10 at 18:26
  • I agree that it is a bad idea to change the question - but the question was never changed - I just added tags. – Faisal Vali Apr 17 '10 at 02:49
  • Personally I'm such a huge fan of *rsync* that I tend to use it even when copying files around locally. OK, not when I have only a simple copy operation ahead, but during larger transfers, yes. Why? Because rsync has great versatility when it comes to recursive transfers, dry runs, including/excluding, preserving various permissions, continuing interrupted operations and so on. – Janne Pikkarainen Aug 03 '10 at 06:02

3 Answers3

49

Execute:

alias cp

To see if cp has been aliased to cp -i

In that case run:

\cp -r /usr/share/drupal-update/* /usr/share/drupal 

to ignore the alias

Eric Leschinski
  • 4,031
  • 4
  • 20
  • 27
Duane
  • 616
  • 5
  • 3
  • I would suggest finding where the alias was made and removing it... hopefully they put it in a local file. This hand holding is on my reasons for not using *buntu – xenoterracide Aug 03 '10 at 06:11
  • This is an old thread, but Ive upgraded to Fedora 19, and this happened to. Someone defaulted an alias for cp –  Feb 04 '14 at 19:50
  • To use the original command, rather than the ailas, use `command cp ...` – ltn100 Jan 05 '16 at 10:42
  • 2
    You can also do an `unalias cp` in that case. – Dominique Apr 01 '16 at 07:51
3

cp -f will not ask for confirmation (that's force) So do

cp -fr /usr/share/drupal-update/* /usr/share/drupal
pehrs
  • 8,749
  • 29
  • 46
  • cp -fr is still asking for confirmation :( – Faisal Vali Mar 06 '10 at 16:18
  • --remove-destination maybe? – TonyUser Mar 06 '10 at 16:26
  • --remove-destination can indeed help in that case. It's typically an access rights problem if it's needed. – pehrs Mar 06 '10 at 16:34
  • 2
    cp -fr still asks for confirmation if it has an alias with interactive: "alias cp='/bin/cp -i'". You either need to unalias cp: "unalias cp" or you can run without the alias using \: "\cp -r /bla/ /foo/". See Duane's answer above. – andrei Oct 24 '12 at 13:48
1

Yea the reason for cp command to be interactive because in many common shells by default copy comes with alias as cp -i this can be found by running command as follows :

alias cp

output will be

alias cp='cp -i'

There are different ways to solve it. Solutions are :

Solution 1. Set alias for that session/permanently in the system or offload alias for cp command.

unset alias: will remove alias for that command. unalias cp

or

resetting alias:

alias cp='cp'

the above command will set alias for cp to be just cp itself instead of cp -i. So you can run copy commands as many as you want without interactive mode just for that terminal session only(temporary). To make that permanent you may reset alias in respective files say

Bash – ~/.bashrc
ZSH – ~/.zshrc
Fish – ~/.config/fish/config.fish

Solution 2. Run with cp command with a backslash \ at the beginning of the copy command.

\cp foo.log /tmp/

This will effectively ignores the alias for the cp command just for that command only.

Inference: Solution 1 is good to set it temporary or permanent if you intend to run lot of cp commands and you want to turn off the interactive mode.

Solution2 is good if you only have couple of cp commands only and don't want to reset the alias, this will be good.

SAGAR Nair
  • 133
  • 8