Copy over existing files without confirmation?

  • 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?

  • 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

    +1 for pointing at how to bypass an alias. Tempted to -1 for the brute force solution.

    +! for the `yes` pipe function - very handy!

    what does -rpf do? I have seen it used multiple times in scripts.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM