bug-coreutils
[Top][All Lists]
Advanced

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

Re: Unexpected behavior in mv


From: Jim Meyering
Subject: Re: Unexpected behavior in mv
Date: Fri, 25 Apr 2003 09:00:51 +0200

"Mario J. Borgnia" <address@hidden> wrote:
> I was surprised when I gave mv a list (using *) as a source and no
> destination. The result was that all files were moved to the last
> directory in the list. Is this the expected behavior?
>
> Example and steps to reproduce
>
> address@hidden tmp]$ echo foo > foo
> address@hidden tmp]$ echo bar > bar
> address@hidden tmp]$ mkdir eenie
> address@hidden tmp]$ mkdir meenie
> address@hidden tmp]$ ls -l
> total 16
> -rw-r--r--    1 me     users           4 Apr 24 15:50 bar
> drwxr-xr-x    2 me     users        4096 Apr 24 15:50 eenie
> -rw-r--r--    1 me     users           4 Apr 24 15:50 foo
> drwxr-xr-x    2 me     users        4096 Apr 24 15:56 meenie
> address@hidden tmp]$ mv *
> address@hidden tmp]$ ls -l
> total 4
> drwxr-xr-x    2 me     users        4096 Apr 24 15:56 meenie

That is beyond the control of `mv'.
It is possible that some shell detects such usage
and diagnoses it.  I know that zsh can do similar things.

> This other case is MUCH more disturbing
>
> address@hidden tmp]$ ls -l
> total 8
> -rw-r--r--    1 me     users           4 Apr 24 15:50 bar
> -rw-r--r--    1 me     users           4 Apr 24 15:50 foo
> address@hidden tmp]$ mv *
> address@hidden tmp]$ ls -l
> total 4
> -rw-r--r--    1 me     users           4 Apr 24 15:50 foo
>
> In this case bar overwrote foo. SCARY...
>
> In case this is the intended behavior, is there any way of protecting
> from this?
> I guess I would gain partial protection by always using the -i flag

A lot of people like to use -i for that.
Personally, I really dislike being prompted, so I use
the --backup=numbered option instead.  Using that in the above
example, foo would not have been lost, but merely renamed to foo.~1~.




reply via email to

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