emacs-bug-tracker
[Top][All Lists]
Advanced

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

[debbugs-tracker] bug#15105: closed ([mv] overwrite files unexpectedly)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#15105: closed ([mv] overwrite files unexpectedly)
Date: Thu, 15 Aug 2013 16:52:03 +0000

Your message dated Thu, 15 Aug 2013 10:51:02 -0600
with message-id <address@hidden>
and subject line Re: bug#15105: [mv] overwrite files unexpectedly
has caused the debbugs.gnu.org bug report #15105,
regarding [mv] overwrite files unexpectedly
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
15105: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15105
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: [mv] overwrite files unexpectedly Date: Thu, 15 Aug 2013 23:16:48 +0800 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0
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









--- End Message ---
--- Begin Message --- Subject: Re: bug#15105: [mv] overwrite files unexpectedly Date: Thu, 15 Aug 2013 10:51:02 -0600 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8
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

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---

reply via email to

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