bug-coreutils
[Top][All Lists]
Advanced

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

Re: cp/mv: add -n option to not overwrite target (Ubuntu bug #229182)


From: Pádraig Brady
Subject: Re: cp/mv: add -n option to not overwrite target (Ubuntu bug #229182)
Date: Tue, 23 Dec 2008 00:37:54 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Eric Blake wrote:
>>> cp [-Pfip] source_file target_file
>> Thanks for the clarification. So POSIX mandates all of -fin are allowed,
>> the last taking precedence. I presume it also means warnings should not be
>> printed.
> 
> No, POSIX only mandates -fi.  -n is an extension, so we can make it
> behave however we'd like (although consistent behavior goes a long way).
> 
>> In any case I think the `mv` descriptions should we reworded to something
>> like:
>>
>> -f    rename a file even if the destination is present and not writable
>>       (overrides any previous -i or -n option).
> 
> Not quite.  -f and -i do not override each other.  Per POSIX, they
> affect independent code paths, such that:
> 
> cp
> cp -f
> cp -i
> cp -f -i (also spelled cp -i -f)
> 
> have four different behaviors.

OK I had missed the asymmetry between the
-f options of mv and cp.

The descriptions in Kamil's patch look correct so.

For my own reference this is how I now see
the overwrite characteristics of cp & mv:

cp : default overwrite method = truncate only (file must be writable)
  -f overwrite method = truncate falling back to unlink+create
     (redundant if the -n option is used)
  --remove-destination
     overwrite method = unlink+create
     (redundant if the -n option is used)
  -i prompt before trying to overwrite dest
     (overrides any preceeding -n option)
  -n never overwrite
     (overrides any preceeding -i option)

mv : prompt to overwrite if dest not writable
  -f never prompt before overwriting
     (overrides any preceeding -i or -n options)
  -i always prompt before overwriting
     (overrides any preceeding -f or -n options)
  -n never overwrite
     (overrides any preceeding -f or -i options)

p.s. According to the FreeBSD manpages referenced in this thread,
cp -f in FreeBSD doesn't conform to POSIX, and instead
means as I originally thought: "try best to overwrite _and don't prompt_."
I.E. it overrides any preceeding -i or -n options.

cheers,
Pádraig.




reply via email to

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