Subject: Re: bug#6023: An enhancement request for the Cp command.

From: Bob Proulx <[email-masked]>
Date: Sat, 24 Apr 2010 13:32:19 -0600

forcemerge 6022 6023
severity 6023 wishlist
tags 6023 + moreinfo
retitle 6023 cp: Make --backup the default
thanks

Salvador wrote:
> Salvador wrote:
>> I want to request a feature for the Cp command that consist in  
>> renaming a file from the source when a file in the destination  
>> directory with the same name already exists. I am thought It could be  
>> something like: from file.jpg to file-1.jpg.
>> This behavior already exists in Web browsers and file managers.
>> Thanks.
> Also, I know about the backup argument but it makes the file not being  
> possible to use by some programs without being renamed.

As you say the feature already exists with 'cp --backup[=CONTROL]' and
therefore you already have that behavior available to you.  If I
understand what you are saying then you are asking for it to be made
the default behavior.  But if that were done it would break 40 years
of Unix behavior.  It is not wise to make such changes.  In order to
stabilize the Unix API the POSIX standard defines the cp behavior that
everyone can rely upon having here:

  http://www.opengroup.org/onlinepubs/009695399/utilities/cp.html

If you desire to have a command that defaults to making a backup all
of the time you may easily do so by creating a differently named
command.  This would avoid breaking legacy applications because it
wouldn't change the behavior of the cp command upon which everyone
counts on.  You could name it 'cpbak' or some such name.

  #!/bin/sh
  exec cp --backup "$@"

Bob