Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cp and mv commands (copying/moving only if file does not exist, regardless of the time stamps, for use in a automatic script)

710 views
Skip to first unread message

Darren DeHaven

unread,
Mar 27, 2008, 5:33:56 PM3/27/08
to bug-...@gnu.org
I need the deprecated mv and cp command parameter "--reply=" to stay.


I've noticed that the parameter "--reply=no" is "deprecated"

" cp: the --reply option is deprecated; use -i or -f instead "


My issue: In a script without user input, I want to copy a file to a
directory if only the file doesn't already exist, (I don't want to
overwrite anything), and regardless of the time stamp.

The only way I see to do this is with the deprecated parameter:
"-i --reply=no"

Example:
"cp -i --reply=no foo bar"

This way if bar exist, then foo won't overwrite it.


Thanks,
~Darren

--
This message (including attachments) contains information which is
confidential and privileged. Unless you are the intended recipient, you
may not use, copy, disseminate or disclose to anyone the message or any
information contained in the message. Proteus submits this email with
the understanding that it will be held in the strictest confidence and
will not be used, in whole or in part, for any purpose other than the
evaluation of Proteus' qualifications without the prior written consent
of Proteus, Inc. If you have received the message in error, please
advise the sender by reply email and delete the message.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Eric Blake

unread,
Mar 27, 2008, 10:54:04 PM3/27/08
to Darren DeHaven, bug-...@gnu.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Darren DeHaven on 3/27/2008 3:33 PM:


| I need the deprecated mv and cp command parameter "--reply=" to stay.

But since bash does not implement mv or cp, you've complained to the wrong
list. This decision has been rehashed a number of times on the
bug-coreutils list, you may want to search the archives for more rationale
why the change was made (hint: the --reply options did not always work
intuitively - they only took effect IF the command was going to prompt in
the first place, and the POSIX rules for when to prompt are pretty hairy).
~ At any rate, I suggest looking into rsync, which can do exactly what you
want and more.

- --
Don't work too hard, make some time for fun as well!

Eric Blake eb...@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkfsXcwACgkQ84KuGfSFAYCLQwCfXn9qxfKBB/oaWSCi/QHoSwsT
zZkAoKtKg2M0yvY76tw5289zDqakwwP/
=SCfx
-----END PGP SIGNATURE-----


Bob Proulx

unread,
Mar 27, 2008, 11:00:17 PM3/27/08
to Darren DeHaven, bug-...@gnu.org
Darren DeHaven wrote:
> I need the deprecated mv and cp command parameter "--reply=" to stay.

The problem is that it never worked as desired.

> I've noticed that the parameter "--reply=no" is "deprecated"
>
> " cp: the --reply option is deprecated; use -i or -f instead "

Yes. See this reference for more information.

http://www.gnu.org/software/coreutils/faq/#cp-and-mv-the-reply-option-is-deprecated

The problem is that --reply=no only had an affect when the command
would normally have prompted. In particular it had no effect when the
command would *not* have prompted. This could lead to silent data
loss. Silent data loss is very, very bad. See this message for
examples:

http://lists.gnu.org/archive/html/bug-coreutils/2005-06/msg00172.html

> My issue: In a script without user input, I want to copy a file to a
> directory if only the file doesn't already exist, (I don't want to
> overwrite anything), and regardless of the time stamp.
>
> The only way I see to do this is with the deprecated parameter:
> "-i --reply=no"

The solution is to use rsync instead.

$ rsync --ignore-existing foo bar

> Example:
> "cp -i --reply=no foo bar"
>
> This way if bar exist, then foo won't overwrite it.

That is incorrect. It will overwrite the file if the input is
redirected such as when run from cron or when the input is redirected
by the user. If the input is not a tty then the command would not
normally prompt. When the command does not prompt the reply is not
used. In that case the target is overwritten.

> This message (including attachments) contains information which is
> confidential and privileged.

Please see:

http://goldmark.org/jeff/stupid-disclaimers/

Bob


aci...@gmail.com

unread,
Apr 8, 2008, 12:49:13 AM4/8/08
to
On Mar 28, 1:00 pm, b...@proulx.com (Bob Proulx) wrote:
> Darren DeHaven wrote:
> > I need the deprecated mv and cp command parameter "--reply=" to stay.
>
> The problem is that it never worked as desired.
>
> > I've noticed that the parameter "--reply=no" is "deprecated"
>
> > " cp: the --reply option is deprecated; use -i or -f instead "
>
> Yes.  See this reference for more information.
>
>  http://www.gnu.org/software/coreutils/faq/#cp-and-mv-the-reply-option...


Hey,

A work around -
in dir your copying to ls > txt
copy txt to dir your copying from
ls `cat txt` > txt2 (outputs matching files)
rm `cat txt2` (removes files existing in this dir that you dont want
to replace)
mv -i source files to target dir (you should see no interaction
messages)

Andy

0 new messages