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!
Execute:
To see if
cp
has been aliased tocp -i
In that case run:
to ignore the alias
cp -f will not ask for confirmation (that's force) So do
Yea the reason for
cp
command to be interactive because in many common shells by default copy comes with alias ascp -i
this can be found by running command as follows :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 justcp
itself instead ofcp -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 saySolution 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.