bug-fileutils
[Top][All Lists]
Advanced

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

[Bug-fileutils] "mv" command -- Unexpected Behavior on Linux


From: Steve Kann
Subject: [Bug-fileutils] "mv" command -- Unexpected Behavior on Linux
Date: Tue, 19 Sep 2000 20:23:27 -0400
User-agent: Mutt/1.2i

Hello fileutils maintainers,

        I'm forwarding this thread to you that clearly describes an
"unexpected behavior" in the gnu mv command (4.0p).  I'll leave it to
you to decide if you think it's a "bug" or not, but I'd call it such --
I'm sure that I'm not the only one that regularly uses the expression
"mv * new_directory" to move files into a subdirectory, expecting mv to
do what we've intended, and just complain about not being able to move
new_directory into itself.

        We've worked around the issue in the script we were writing (by
basically re-writing mv in perl for this), so this is really just a
heads-up for you.

        Thanks.  Please feel free to contact Lenny or Charles if you
have any questions about their tests.   

----- Forwarded message from Steve Kann <address@hidden> -----

Date: Tue, 19 Sep 2000 20:15:50 -0400
From: Steve Kann <address@hidden>
To: Lenny Mastrototaro <address@hidden>
Cc: Charles Wang <address@hidden>, address@hidden
Subject: Re: bad idea (was Re: "mv" command -- Unexpected Behavior on Linux)
Delivered-To: address@hidden
Delivered-To: address@hidden
Delivered-To: address@hidden
X-Authentication-Warning: canarsie.horizonlive.com: stevek set sender to 
address@hidden using -f
User-Agent: Mutt/1.2i
X-Blank-Header-Line: (this header intentionally left blank)


Interesting, Lenny..

I'd say this is a bug in "mv", though, and it's probably not how i would
have written it.. 

Apparently, some "clever" gnu guys thought that adding the feature of
being able to "mv" directories across filesystems would be helpful.
Their implementation of that causes this behavior.

Traditionally, mv would either rename() files or directories, or copy
and remove the original for files.

It didn't have any "recursive directory copy" functionality.  It is this
recursion that causes this problem, and which does not exist in the old
mv command since back in V7 Unix.

>From "info mv":
           `mv' can move any type of file from one filesystem to
           another.  Prior to version `4.0' of the fileutils, `mv' could
           move only regular files between filesystems.  For example,
           now `mv' can move an entire directory hierarchy including
           special device files from one partition to another.  It first
           uses some of the same code that's used by `cp -a' to copy the
           requested directories and files, then (assuming the copy
           succeeded) it removes the originals.  If the copy fails, then
           the part that was copied to the destination partition is
           removed.  If you were to copy three directories from one
           partition to another and the copy of the first directory
           succeeded, but the second didn't, the first would be left on
           the destination partion and the second and third would be
           left on the original partition.

I think that this behavior is probably better left to "cp -a", and
shouldn't have been added to mv.  (maybe as an optional feature, like mv
-a or something..).

Personally, I'd send this in as a bug..  Maybe I'll do that now.

-SteveK


On Tue, Sep 19, 2000 at 06:51:50PM -0400, Lenny Mastrototaro wrote:
> On Tue, Sep 19, 2000 at 05:15:45PM -0400, Steve Kann wrote:
> > On Wed, Sep 13, 2000 at 12:33:35PM -0400, Charles Wang wrote:
> > > Hi,
> > > 
> > > It seems that the "mv" command has some unexpected behavior on linux.
> > > 
> > > The scenarios are:
> > > 
> > > a. in a directory, you have only one sub dir (called web), and a 
> > > number of files named f1, f2, and f3.
> > > 
> > > address@hidden charles]$ ls -l
> > > total 4
> > > -rw-r--r--   1 charles  charles         0 Sep 13 12:13 f1
> > > -rw-r--r--   1 charles  charles         0 Sep 13 12:13 f2
> > > -rw-r--r--   1 charles  charles         0 Sep 13 12:13 f3
> > > drwxr-xr-x   2 charles  charles      4096 Sep 13 12:13 web
> > > 
> > > Then you do "mv * web", trying to move everything in the current dir 
> > > to the web sub dir:
> > > 
> > > address@hidden charles]$ mv * web
> > > mv: cannot move `web' to a subdirectory of itself, `web/web'
> > > 
> > > address@hidden charles]$ ls
> > > web
> > > address@hidden charles]$ ls web
> > > f1  f2    f3
> > > 
> > > This is the right behavior (at least the same on unix), but not
> > > in the case b shown below.
> > > 
> > > b. you have one more sub dir called d1 besides the ones you 
> > > have in case a:
> > > 
> > > address@hidden charles]$ ls -l
> > > total 8
> > > drwxr-xr-x   2 charles  charles      4096 Sep 13 12:19 d1
> > > -rw-r--r--   1 charles  charles         0 Sep 13 12:13 f1
> > > -rw-r--r--   1 charles  charles         0 Sep 13 12:13 f2
> > > -rw-r--r--   1 charles  charles         0 Sep 13 12:13 f3
> > > drwxr-xr-x   2 charles  charles      4096 Sep 13 12:19 web
> > > 
> > > Now you try to do the same thing as in case a:
> > > 
> > > address@hidden charles]$ mv * web
> > > mv: web/web/d1: won't create hard link `web/web' to directory `(null)'
> > > 
> > > address@hidden charles]$ ls   
> > > web
> > > address@hidden charles]$ ls web
> > > d1  f1    f2  f3  web
> > > address@hidden charles]$ ls web/web
> > > f1  f2    f3
> > > 
> > > Please note that, it does create the web/web (seems to be a hard link).
> > > On unix, it won't create web/web which makes more sense to me (consistent 
> > > with
> > > or without the additional sub, d1).
> > 
> > Charles,
> > 
> > This is an interesting phenomena that you have shown, but I can't seem
> > to replicate it here.  I tried it both on a local direcory, as well as
> > one on a nfs-mounted share.  Linux or any other unix should not allow
> > you to create a hard link to a direcory anymore.  (you used to be able
> > to, I think, in the "old days", i.e. before there was a "mkdir" system
> > call, and you had to make directories from user space).
> > 
> > Is the directory "charles" located on the machine "w12", or is is
> > mounted remotely, somehow?  What kernel are you running on "w12"?
> > 
> > Can you do a "ls -lai" on the directories before and after?  This will
> > tell us more clearly what's a symlink, what's a hard link, etc.
> 
> Charles,
> 
> using the * in the mv statement is asking for trouble since
> the number and order of operations will depend on the name 
> of the files and directories you're moving. For example, if 
> the current directory conisted of:
> 
>     a1        directory
>     d1        directory
>     f1        file
>     f2        file
>     f3        file
> 
> the `mv * a1' command would have a different result because of
> the order of operations. Use the -v option with mv to watch it
> work.
> 
> for example:
> 
>     # starting fresh
>     mkdir web
>     touch f1 f2 f3
>     ls -lai
> 
>         total 12
>       1453175 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 17:58 .
>       1371145 drwxrwxr-x  15 lenny    lenny        4096 Sep 19 17:40 ..
>       1453213 -rw-rw-r--   1 lenny    lenny           0 Sep 19 17:58 f1
>       1453214 -rw-rw-r--   1 lenny    lenny           0 Sep 19 17:58 f2
>       1453215 -rw-rw-r--   1 lenny    lenny           0 Sep 19 17:58 f3
>       1453176 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 17:58 web
> 
>     # notice the glob order
>     echo *
> 
>         f1 f2 f3 web
> 
>     mv -v * web
> 
>         f1 -> web/f1
>       f2 -> web/f2
>       f3 -> web/f3
>       web -> web/web
>       web/f1 -> web/web/f1
>       web/f2 -> web/web/f2
>       web/f3 -> web/web/f3
>       mv: cannot move `web' to a subdirectory of itself, `web/web'
>       removing all entries of directory web/web
>       removing web/web/f1
>       removing web/web/f2
>       removing web/web/f3
>       removing the directory itself: web/web
> 
>     ls -lai
> 
>         total 12
>       1453175 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:00 .
>       1371145 drwxrwxr-x  15 lenny    lenny        4096 Sep 19 17:40 ..
>       1453176 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:00 web
> 
>     ls -lai web
> 
>         total 8
>       1453176 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:00 .
>       1453175 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:00 ..
>       1453213 -rw-rw-r--   1 lenny    lenny           0 Sep 19 17:59 f1
>       1453214 -rw-rw-r--   1 lenny    lenny           0 Sep 19 17:59 f2
>       1453215 -rw-rw-r--   1 lenny    lenny           0 Sep 19 17:59 f3
> 
>     # start again, this time add a directory d1
>     mkdir web d1
>     touch f1 f2 f3
>     ls -lai
> 
>         total 16
>       1453222 drwxrwxr-x   4 lenny    lenny        4096 Sep 19 18:08 .
>       1371145 drwxrwxr-x  17 lenny    lenny        4096 Sep 19 18:08 ..
>       1453224 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:08 d1
>       1453225 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:08 f1
>       1453226 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:08 f2
>       1453227 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:08 f3
>       1453223 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:08 web
> 
>     echo *
> 
>         d1 f1 f2 f3 web
> 
>     mv -v * web
> 
>         d1 -> web/d1
>       f1 -> web/f1
>       f2 -> web/f2
>       f3 -> web/f3
>       web -> web/web
>       mv: web/web/d1: won't create hard link `web/web' to directory `(null)'
>       web/f1 -> web/web/f1
>       web/f2 -> web/web/f2
>       web/f3 -> web/web/f3
> 
>     # start again with differently named directories
>     mkdir a1
>     touch f1 f2 f3
>     ls -lai
> 
>         total 12
>       1681703 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:11 .
>       1371145 drwxrwxr-x  18 lenny    lenny        4096 Sep 19 18:10 ..
>       1681704 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:11 a1
>       1681705 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:11 f1
>       1681706 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:11 f2
>       1681707 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:11 f3
> 
>     echo *
> 
>         a1 f1 f2 f3
> 
>     mv -v * a1
> 
>         a1 -> a1/a1
>       mv: cannot move `a1' to a subdirectory of itself, `a1/a1'
>       removing all entries of directory a1/a1
>       removing the directory itself: a1/a1
>       f1 -> a1/f1
>       f2 -> a1/f2
>       f3 -> a1/f3
> 
>     ls -lai
>     
>         total 12
>       1681703 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:11 .
>       1371145 drwxrwxr-x  18 lenny    lenny        4096 Sep 19 18:10 ..
>       1681704 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:11 a1
> 
>     ls -lai a1
> 
>         total 8
>       1681704 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:11 .
>       1681703 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:11 ..
>       1681705 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:11 f1
>       1681706 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:11 f2
>       1681707 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:11 f3
> 
>     # start again with added directory d1
>     mkdir a1 d1
>     touch f1 f2 f3
>     ls -lai
> 
>         total 16
>       1453216 drwxrwxr-x   4 lenny    lenny        4096 Sep 19 18:02 .
>       1371145 drwxrwxr-x  16 lenny    lenny        4096 Sep 19 18:02 ..
>       1453217 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:02 a1
>       1453218 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:02 d1
>       1453219 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:02 f1
>       1453220 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:02 f2
>       1453221 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:02 f3
> 
>     # notice the glob order
>     echo *
> 
>         a1 d1 f1 f2 f3
> 
>     # notice the totally differnt number and order of operations
>     # even though we're using a very similar command.
>     mv -v * a1
> 
>         a1 -> a1/a1
>       mv: cannot move `a1' to a subdirectory of itself, `a1/a1'
>       removing all entries of directory a1/a1
>       removing the directory itself: a1/a1
>       d1 -> a1/d1
>       f1 -> a1/f1
>       f2 -> a1/f2
>       f3 -> a1/f3
> 
>     ls -lai
> 
>         total 12
>       1453216 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:04 .
>       1371145 drwxrwxr-x  16 lenny    lenny        4096 Sep 19 18:02 ..
>       1453217 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:04 a1
> 
> 
>     ls -lai
> 
>         total 12
>       1453217 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:04 .
>       1453216 drwxrwxr-x   3 lenny    lenny        4096 Sep 19 18:04 ..
>       1453218 drwxrwxr-x   2 lenny    lenny        4096 Sep 19 18:02 d1
>       1453219 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:02 f1
>       1453220 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:02 f2
>       1453221 -rw-rw-r--   1 lenny    lenny           0 Sep 19 18:02 f3
> 
> 
> perhaps you should use a combination of find and xargs or perhaps
> the File::Find perl module to have better control over the operation.
> 
> Regards,
> Lenny
> 
> -- 
> Lenny Mastrototaro          Director of System and       HorizonLive.com
> address@hidden       Network Administration         (212)813-3867
> 
>                         collaborate . interact . learn

-- 
  Steve Kann - Chief Engineer - 520 8th Ave #2300 NY 10018 -  (212) 533-1775
                HorizonLive.com - collaborate . interact . learn
   "The box said 'Requires Windows 95, NT, or better,' so I installed Linux."

----- End forwarded message -----

-- 
  Steve Kann - Chief Engineer - 520 8th Ave #2300 NY 10018 -  (212) 533-1775
                HorizonLive.com - collaborate . interact . learn
   "The box said 'Requires Windows 95, NT, or better,' so I installed Linux."


reply via email to

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