Qooe
Qooe

Reputation: 673

Linux command to move a directory

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?

Upvotes: 26

Views: 59737

Answers (5)

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

Upvotes: 4

Manish Trivedi
Manish Trivedi

Reputation: 3559

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/

Upvotes: 1

Henry Killinger
Henry Killinger

Reputation: 11

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.

Upvotes: 1

Paweł Polewicz
Paweł Polewicz

Reputation: 3831

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.

Upvotes: 6

alamar
alamar

Reputation: 19313

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.

Upvotes: 32

Related Questions