in reply to Re^3: file::move and networks
in thread file::move and networks

Un*x does not do that, you need 'mv -f file1 file2' to force the mv on existing file

That's not true. The default behavior for cp, rm, and mv is to behave as if '-f' was specified on the command line.

I think you are confused because all three of these commands are usually aliased to 'cp -i', 'rm -i', and 'mv -i' respectively. Run 'alias' to see this. The '-f' option is useful because it overrides the '-i', though you could also escape the alias ('\mv') or full path the comamnd ('/bin/mv') to achieve the same results.

Replies are listed 'Best First'.
Re^5: file::move and networks
by sgt (Deacon) on Jul 17, 2007 at 09:53 UTC

    Quite true. Thanks to both of you.

    You need more trickery to achieve the other semantics. Probably not very portable and means there should be a special flag for "don't overwrite" mode.

    % steph@ape2 (/home/stephan) % % ll $0 lrwxrwxrwx 1 steph Ninguno 47 Mar 5 15:07 /bin/ksh93 -> /usr/ast-ksh9 +3s/arch/cygwin.i386/bin/ksh93s.exe % steph@ape2 (/home/stephan) % % echo foo > foo; echo bar > bar; /bin/ls -l foo bar; /bin/mv 0<&- 2>& +- -i foo bar; cat -evnt bar -rw-r--r-- 1 steph Ninguno 4 Jul 17 11:36 bar -rw-r--r-- 1 steph Ninguno 4 Jul 17 11:36 foo 1 bar$

    Looking at version 3 of the single Unix Specification mv seems to indicate the above trick is ok from a standard perspective.

    cheers --stephan