mv * not working

hi,

I am trying as below
mv * to move multiple files but not working
http://www.thegeekstuff.com/2010/12/mv-command-examples/
$ 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                                                                                                                                      
/home/cg/root                                                                                                                                      


please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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

0
Gerwin Jansen, EE MVETopic Advisor Commented:
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:

file1.txt
file2.txt
file3.c
file4.doc
folder1/
folder2/

To move all files to folder1 do this:

mv file* folder1/

To move all .c files to folder2 do this:

mv *.c folder2/

etc.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skullnobrainsCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.