19

What I've tried:

root@host [/home1]# cp -f hello /home3
cp: omitting directory `hello'
root@host [/home1]# cp -rf hello /home3
cp: overwrite `/home3/hello/.buildpath'? y
cp: overwrite `/home3/hello/.bash_logout'? y
cp: overwrite `/home3/hello/.project'? ^C

They always ask me whether I want to overwrite. Using mv doesn't work either. So what should I do?

Other things I tried:

root@host [/home1]# cp -rf hello /home3
cp: overwrite `/home3/hello/.buildpath'? y
cp: overwrite `/home3/hello/.bash_logout'? y
cp: overwrite `/home3/hello/.project'? ^C
root@host [/home1]# cp -force hello /home3
cp: invalid option -- 'o'
Try `cp --help' for more information.
root@host [/home1]# cp --remove-destination hello /home4
cp: omitting directory `hello'
root@host [/home1]# cp --remove-destination hello /home3
cp: omitting directory `hello'
root@host [/home1]# cp --remove-destination -r hello /home3
cp: overwrite `/home3/hello/.buildpath'? ^C
root@host [/home1]#
3
  • 2
    Could you give the output of alias cp? Commented Jul 18, 2013 at 13:04
  • 2
    Also, type cp as well as ls -l on one of the target files may provide useful information.
    – user
    Commented Jul 18, 2013 at 13:36
  • cp is copy. Okay it may be an alias. So what's the command?
    – user4951
    Commented Aug 9, 2013 at 3:07

6 Answers 6

20

For force overwrite without asking you should use the command mv and the option "-f", use man to see the options.

man mv:

   -f, --force
          do not prompt before overwriting

Example:

mv -f test.tmp test.txt
1
  • FYI, on macOS --force can't be used. Just -f. I know, I was surprised as well. I usually like to use the more explicit options when they are available, but in this case it's not - on macOS anyway. Commented Aug 3, 2021 at 21:04
15

cp appears to be either aliased to something which is causing problems, or it is a function. You can remove the alias/function:

unalias cp
unset -f cp

If you'd rather just override it right now, you can use the command command to override any alias/function definitions:

command cp [...]

If you'd rather totally remove this, you probably have to look in your bash startup files.

2
  • 4
    \cp will also avoid the alias. Commented Jul 18, 2013 at 14:27
  • Yup, you are correct which cp => alias cp='cp -i; /bin/cp. Thanks Amazon!
    – Gerry
    Commented May 5, 2015 at 0:51
2

You probably have an alias for cp. You can override this alias by doing:

\cp -f hello /home3

This has the adventage of not modifying your aliases setup, as it is overriding it just for this call.

1

Try cp -rv /sourcefileordirectory /Destinationfolder

2
  • will t his work? What does -rv mean?
    – user4951
    Commented Aug 9, 2013 at 3:08
  • -rv means recursive and verbose. So this should copy the files and subfolders, and output the progress to the terminal.
    – JNat
    Commented Mar 12, 2015 at 22:20
0

You can use yes, which is designed for this sort of thing. It will automatically print y and answer these prompts for you:

yes | cp -f hello /home3
0

just execute alias cp=cp and it will overwrite the target without asking in this session. If you want to have it stored as standard behavior, store it in your ~/.bashrc.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .