Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux command to move a directory

Tags:

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?

like image 280
Qooe Avatar asked May 15 '09 11:05

Qooe


People also ask

How do I move a directory?

Select the directory you want to move and press Ctrl+X. Alternatively, right-click the directory and select Cut from the drop-down menu. 2. Navigate to the destination and press Ctrl+V or right-click the empty space and select Paste from the drop-down menu to move the directory.

Which command is used to move directory?

The mv command moves files and directories from one directory to another or renames a file or directory. If you move a file or directory to a new directory, it retains the base file name. When you move a file, all links to other files remain intact, except when you move it to a different file system.


1 Answers

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.

like image 85
alamar Avatar answered Oct 16 '22 10:10

alamar