tags:

views:

67

answers:

4

I want to move all the files to a new dir. From the command line I can do "mv . newdir" but if I try with this script:

#!/bin/bash -f
#
mkdir newdir
mv *.* newdir

I get the following message:

mv: rename *.* to newdir/*.*: No such file or directory
+1  A: 

If you want to move all files, try this:

mkdir newdir

find . -type f -exec mv "{}" newdir \;

Amardeep
why not safe?..
Juliano
Because "mv . newdir" attempts to move your current directory into a subdirectory and makes no sense.
Amardeep
May make no sense, it may be invalid, but it is not unsafe. You suggestion moves only files, leaving directories in the same place. So it has a very different meaning than what the poster is trying to do.
Juliano
I concede to your point about safety! I'm editing that out of my answer.
Amardeep
+1  A: 

The first line of your script reads like:

#!/bin/bash -f

You are passing the -f switch to bash when the script is invoked. This causes the shell to disable file name expansion, which is also known as globbing or pattern matching. Remove that -f from the shebang line.

Also, you should note that to select all files in bash you use just "*", and not "*.*". The later would select only files with a dot in their names. This may also cause you to try to put the directory into itself, which is an invalid operation.

Juliano
A: 

mmm... I do not why but the script is not clear in my post... it goes again:

!/bin/csh -f

mkdir newdir

mv . newdir

Anxo
You can't move . . and you shouldn't script in csh.
reinierpost
If you need to add more information to your question, use the "edit" link below the question to edit it. Don't post an answer to your own question unless it's actually an answer.
Syntactic
A: 

Thank you very much!

Anxo
Do not use answers to post such kinds of comments. Use the comments feature for that.
Juliano