bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with cp-command


From: Bob Proulx
Subject: Re: problem with cp-command
Date: Sat, 7 Jul 2007 17:49:05 -0600
User-agent: Mutt/1.5.9i

Peter Landgren wrote:
> However, the "-f" or "--force" flag does not seem to work.  Even
> with it, I get a question about overwriting.
> ...
> address@hidden ~]$ alias cp
> alias cp='cp -i'

In the online standards documentation:

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

  -i  Write a prompt to standard error before copying to any existing
      destination file. If the response from the standard input is
      affirmative, the copy shall be attempted; otherwise, it shall not.

  -f  If a file descriptor for a destination file cannot be obtained, as
      described in step 3.a.ii., attempt to unlink the destination
      file and proceed.

  3.a.ii.  If the attempt to obtain a file descriptor fails and the -f
           option is in effect, cp shall attempt to remove the file by
           performing actions equivalent to the unlink() function
           defined in the System Interfaces volume of IEEE Std
           1003.1-2001 called using dest_file as the path argument. If
           this attempt succeeds, cp shall continue with step 3b.

When 'cp -i -f sourcefile destfile' is invoked then if the file exists
you are prompted due to the -i option as to whether you want to
overwrite the file.  If you answer yes then the output file is opened.
If opening the output file fails then because of the -f option the
output file is removed and the open for writing attempted again.

Summary: As presently implemented in cp the -f does not override the -i.

I am not sure that is the correct behavior though.  Comments from
others?  Shouldn't -f override -i regardless of the POSIX
documentation?  I think that is the behavior on other systems but
can't check right now.

Because you have a command line alias it does not affect scripts or
there would be large problems.  On the command line the 'yes' command
is designed to answer 'y' to questions such as this automatically.
'yes | cp -i -f sourcefile destinationfile' but I myself probably only
use the yes command once a year at most.  Better to simply remove the
command line alias and avoid the issue entirely.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]