Search code examples
tcshcp

Force cp to overwrite when -i option used by defaul


I use c shell (tcsh specifically).

I have the following alias in my .custom file, so that cp by default is always defined to have the -i flag:

alias cp cp -i

For a specific shell script I am trying to write it is desirable for cp to be forced to overwrite and not prompt me if I want to overwrite the destination file. I have tried using cp --remove-destination in my shell script but I was still being prompted whether to overwrite the destination files. What would be the correct flag to use to force an overwrite when -i is already the default behavior?


Solution

  • You have two possibilities:

    First uses system cp instead of invoking your alias:

    /bin/cp .....
    

    Second overrides -i option (so it looks like cp -i -n instead)

    cp -n ....
    

    The second one is much less readable so I suggest using the first one.