Subject: bug#15105: closed (Re: bug#15105: [mv] overwrite files unexpectedly)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 15 Aug 2013 16:52:04 +0000

Your bug report

#15105: [mv] overwrite files unexpectedly

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
15105: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15105
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#15105: [mv] overwrite files unexpectedly
From: Eric Blake <[email-masked]>
To: Hai <[email-masked]>
Cc: [email-masked]
Date: Thu, 15 Aug 2013 10:51:02 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

tag 15105 notabug
thanks

On 08/15/2013 09:16 AM, Hai wrote:
> Hi All
> 
> If someone else have issued this thing before, please forgive my
> disturbance.
> 
> Command $mv a_file* will overwrite one of your files iff 2 files with
> the same prefix under the folder.

Yes, and this is a feature, required by POSIX.

> 
> I know we should know what we are doing with the command given by
> ourselves.
> But I think this is an unusual case, and tools should complain it.

Unfortunately, mv cannot distinguish between 'mv a*' and 'mv a1 a2' -
the globbing has already happened in the shell before mv ever sees its
command line arguments.

> Can mv check the args before parsing the data in it? 'Cause I think no
> body is going to rename a file with this kind of command 'mv a_file*',
> so there should be a potential error, and should better tell the user.

I could suggest that you consider setting up an alias in your
environment, such as:
 alias mv='mv -n '
or
 alias mv='mv -i '
so that if you type 'mv a*' and the glob expands to a valid command that
would overwrite the second file, then it will fail or prompt you.  But
be careful - if you create an alias by the same name, but then use a
different machine where the alias is not active, you may find that you
have become reliant on the alias doing the dirty work for you, and
losing data on the machine that lacks the alias.  Also, this would mean
that mv prompts you even when you spell out the overwrite in longhand,
and you may find yourself needing to use to '\mv a b' to avoid the
alias.  (Personally, I hate distros that pre-alias mv to 'mv -i', and
that's one of the first things that I check for and undo in my
customization of a new account on such a machine - but some people swear
by it, or distros wouldn't do it...)

In short, because there is no way to make mv behave differently if you
used a glob compared to spelling in longhand, and because there is
already an option to prevent overwrites, I don't think we need to change
anything in coreutils, so I'm closing this bug report.  Feel free,
however, to continue the conversation in this thread if you have more
questions or ideas.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Subject: [mv] overwrite files unexpectedly
From: Hai <[email-masked]>
To: [email-masked]
Date: Thu, 15 Aug 2013 23:16:48 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi All

If someone else have issued this thing before, please forgive my 
disturbance.

Command $mv a_file* will overwrite one of your files iff 2 files with 
the same prefix under the folder.

I know we should know what we are doing with the command given by ourselves.
But I think this is an unusual case, and tools should complain it.

Scenario:

$ tree
.
|-- a_file
|-- a_file.c

Having these 2 files under a folder.

And I want to mv these 2 files to another folder with the given 
command('cause I forget to type the destination directory),
so the command will be interpreted to $mv a_file a_file.c, this is a 
totally correct command, so it will be performed perfectly.
but one of my file is overwritten.

Can mv check the args before parsing the data in it? 'Cause I think no 
body is going to rename a file with this kind of command 'mv a_file*',
so there should be a potential error, and should better tell the user.

Regards & Thanks
Hai Guo