How to copy or move files without being asked to overwrite?

104,808

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

Try cp -rv /sourcefileordirectory /Destinationfolder

Share:
104,808

Related videos on Youtube

user2935706
Author by

user2935706

Updated on September 18, 2022

Comments

  • user2935706
    user2935706 almost 2 years

    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]#
    
    • Raphael Ahrens
      Raphael Ahrens almost 11 years
      Could you give the output of alias cp?
    • user
      user almost 11 years
      Also, type cp as well as ls -l on one of the target files may provide useful information.
    • user2935706
      user2935706 almost 11 years
      cp is copy. Okay it may be an alias. So what's the command?
  • sendmoreinfo
    sendmoreinfo almost 11 years
    \cp will also avoid the alias.
  • user2935706
    user2935706 almost 11 years
    will t his work? What does -rv mean?
  • JNat
    JNat over 9 years
    -rv means recursive and verbose. So this should copy the files and subfolders, and output the progress to the terminal.
  • Gerry
    Gerry about 9 years
    Yup, you are correct which cp => alias cp='cp -i; /bin/cp. Thanks Amazon!