Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am at the path:

/myuser/downloads/

And I create a sub folder:

/myuser/downloads/new

Now I want to move all files and folders/sub-folders in the downloads folder to the sub-folder.

how can I do this?

I tried:

mv -R *.* new/

But move doesn't take the -R switch it seems.

share|improve this question
    
You do not need -R. Just mv * new Though, it will whine "cannot move new to new" or something similar. Perhaps mv -i * new to you prevent overwrites. – user8290 Jan 1 '12 at 0:59
up vote 20 down vote accepted

The command

mv !(new) new

should do the trick. If it doesn't work, run shopt -s extglob first.

To also move hidden files/directories (that beginning with a dot), run also shopt -s dotglob first.
So, to sum up:

shopt -s extglob dotglob
mv !(new) new
shopt -u dotglob

(it is always better to unset dotglob to avoid bad surprises).

share|improve this answer
    
Thanks fro your info. It works for me.for an long time i looking for it. – Mughil Jan 1 '12 at 12:24
    
can you mention what is the significance of !(something) ? – a deer Feb 1 at 12:46
    
@adeer that is just saying not(something). In other words, copy everything but not something. Clear as mud? – RockyMountainHigh Feb 25 at 3:33
    
very. do you happen to know the equivalent for zsh ? – a deer Mar 7 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.