26

My old and new directory have same folders and files inside.

I try:

mv -if old/* new/*

and get error

mv: cannot move `./xxxxxx' to a subdirectory of itself

How can I move it?

tom redfern
  • 30,562
  • 14
  • 91
  • 126
Qooe
  • 673
  • 2
  • 7
  • 13

5 Answers5

32

You should use mv -if old/* new/ without the trailing *.

This is because it unrolled to

mv -if old/foo old/bar old/baz new/foo new/bar new/baz

i.e. move everything into new/baz

This is not what you wanted.

alamar
  • 18,729
  • 4
  • 64
  • 97
6
reef@localhost:/tmp/experiment$ ls a
11  22  33
reef@localhost:/tmp/experiment$ ls b
22  33
reef@localhost:/tmp/experiment$ ls
a  b
reef@localhost:/tmp/experiment$ mv a/* b
reef@localhost:/tmp/experiment$ ls a
reef@localhost:/tmp/experiment$ ls b
11  22  33

It works. What are You trying to achieve? Could You please write a short example of what the input data should look like and what the output data should look like? The truth is I have no idea what You are trying to do :) Help me help You.

Paweł Polewicz
  • 3,711
  • 2
  • 20
  • 24
4

note that mv a/* b/ don't move files .* (file name start with '.') in a/ to b/

ex:

$ mkdir -p a/d b && touch a/f a/.f a/d/.f
$ mv a/* b/
$ ls -a a/
.  ..  .f
1

Might be you got the answer but above answer is not working for me.... and finally lots of researching I got the answer. (Issue is due to files-ownership)
and just put sudo before the command and its working.... :) Same thing for cp and mv command.

sudo mv -if old/* new/
Manish Trivedi
  • 3,481
  • 5
  • 23
  • 29
1

If you are copying from an ext2/3/4 file system to a FAT32 file system, and a filename has an invalid character for FAT32 naming conventions, you get this terribly annoying and incorrect as hell error message. How do I know? I wrestled with this bug - yes, it's a KERNEL BUG - for 6 hours before it dawned on me. I thought it was a shell interpreter error, I thought it was an "mv" error - I tried multiple different shells, everything. Try this experiment: on an ext file system, "touch 'a:b'" them "mv" it to a FAT32 file system. Try it, you'll enjoy (hate) the results. The same is true for '<' and '>' (\074 and \076).

Thanks for "man mv" - that's a real big help, don't quit your day job.