How do you do in order not to overwrite some file when using cp? Say we have a source file we cp to an object directory which happens to have a file with the same name as the source file. According to the manual, cp will always overwrite it. Any easy oneliner which includes the cp command in it and warns the user before proceeding?

druuna

11-05-2013 02:44 AM

Quote:

Originally Posted by stf92
(Post 5058580)

How do you do in order not to overwrite some file when using cp? Say we have a source file we cp to an object directory which happens to have a file with the same name as the source file. According to the manual, cp will always overwrite it. Any easy oneliner which includes the cp command in it and warns the user before proceeding?

I was so certain cp provided no way to do it! Thanks and, by the way, how does the typical linux user use cp in this regard. Always with the -i option?

druuna

11-05-2013 03:07 AM

Quote:

Originally Posted by stf92
(Post 5058597)

How does the typical linux user use cp in this regard. Always with the -i option?

I only use the -i option when absolutely necessary (for cp, mv, rm).

Some distro's make a default alias, for the root user, to include the -i option. One of the first things I do is remove that specific alias.

If you do want/need such an alias:

Code:

alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'

Remember: Unix/Linux assumes that you know what you are doing (unlike Windows, which questions just about everything you do).

stf92

11-05-2013 03:28 AM

OK. Now I have cp, which is just that alias, and suppose some other time I want to transitorily go back to normal, just to copy some file. I do not think there is an alternative other than unset the alias, given that options do not generally have a corresponding negative option (in this case, "option" 'do not prompt ...'). Am I right?

druuna

11-05-2013 03:34 AM

You can use \cp to temporarily get rid of all aliases that are in place. This, the use of a leading backslash, isn't limited to the cp command.