We help IT Professionals succeed at work.

mv * not working


I am trying as below
mv * to move multiple files but not working
$ cd chap1

$ ls -F
ex1.c    ex2.c    ex3.c    example/   exercise/  

$ mv * chap2/

bash-4.4$ ls -ltr                                                                                                                                  
total 12                                                                                                                                          
-rw-r--r-- 1 14392 14392  978 Nov 22 16:46 README.txt                                                                                              
-rw-r--r-- 1 14392 14392    7 Nov 22 16:47 456.txt                                                                                                
drwxr-xr-x 2 14392 14392 4096 Nov 22 16:49 dir3                                                                                                    
-rw-r--r-- 1 14392 14392    0 Nov 22 16:56 c.txt                                                                                                  
bash-4.4$ mv * new/                                                                                                                                
mv: target 'new/' is not a directory                                                                                                              
bash-4.4$ mkdir new                                                                                                                                
bash-4.4$ mv * new/                                                                                                                                
mv: cannot move 'new' to a subdirectory of itself, 'new/new'                                                                                      
bash-4.4$ pwd                                                                                                                                      

please advise
Watch Question

David FavorFractional CTO
Distinguished Expert 2019
This makes no sense...

$ cd chap1
$ ls -F
ex1.c    ex2.c    ex3.c    example/   exercise/  
$ mv * chap2/

Open in new window

If you look at the ls output, there is no chap2 in the chap1 directory.

Likely you meant your command to be...

$ mv * ../chap2/.

Open in new window

Topic Advisor
Most Valuable Expert 2016
Your first try is not working because the directory chap2 does not exist. If you want it to work, first create that directory (mkdir chap2) and then perform the mv command.

Note that mv * will also try to move the chap2 folder to the destination, if that is chap2 then you get the "mv: cannot move 'chap2' to a subdirectory of itself, 'chap2/chap2' message.

The mv command is telling you exactly what is cannot do - read the message!

Your second try is working just fine, it only tells you that it cannot mv the new folder to the new folder itself (see message above).

A better way of moving files into a folder is by using a wild card so you can move certain files to a folder.

Consider this:


To move all files to folder1 do this:

mv file* folder1/

To move all .c files to folder2 do this:

mv *.c folder2/

same problem as your other question : use the -T flag when you rename a directory if you do not want to accidentally copy the dir into a subdir of the previously move dir