Re: question about the "copy, then remove" behaviour of mv

Bob Proulx <[email protected]> Mon, 26 Oct 2009 02:49:47 -0600
Newsgroups gmane.comp.gnu.utils
Message-ID <[email protected]>
Musaul Karim wrote:
> ... on a two level deep directory structure with files file1 to 5
> gives me the following output, which seems consistent with what
> happened earlier.

First, for shallow copies I see it interlaced as normal.

  $ mv -v /dev/shm/2/* /tmp/a/1/
  `/dev/shm/2/foo1' -> `/tmp/a/1/foo1'
  removed `/dev/shm/2/foo1'
  `/dev/shm/2/foo2' -> `/tmp/a/1/foo2'
  removed `/dev/shm/2/foo2'
  `/dev/shm/2/foo3' -> `/tmp/a/1/foo3'
  removed `/dev/shm/2/date3'

But for the deeper copies that you pointed out I do see what you are
reporting as well.  Thanks for persevering.  I hadn't considered the
case you were bringing up.

  $ mv -v 1/2 /dev/shm/
  `1/2' -> `/dev/shm/2'
  `1/2/foo1' -> `/dev/shm/2/foo1'
  `1/2/foo2' -> `/dev/shm/2/foo2'
  `1/2/foo3' -> `/dev/shm/2/foo3'
  removed `1/2/foo1'
  removed `1/2/foo2'
  removed `1/2/foo3'
  removed directory: `1/2'

Hmm...  I can only agree that it doesn't seem the best behavior.  I
haven't looked at the code but I can guess that it is looping through
the arguments in the shallow case and recursively descending down
arguments in the deep case.  I am sure that accounts for why the two
cases have different behavior.

If you feel motivated I suggest raising this issue on the
bug-coreutils mailing list.  It seems there would be room for
improvement in the deep hierarchy case.  It may be reasonable to
reorganize the code to remove files earlier even in the recursive
case.

Bob