Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
find . -name *.rb

doesn't work on my ubuntu

I have to do

find . -name "*.rb"

to get it to work.

Why is that?

share|improve this question
    
I cannot say why, but it is the same on Solaris UNIX (when the * is used). I have had to do it that way for many years. –  Tim Mar 13 '12 at 21:48
    
might consult man find –  Ringtail Mar 13 '12 at 22:19
add comment

2 Answers 2

up vote 9 down vote accepted

If you have a file in the current directory ending with .rb, it'll be expanded by the shell. So, if you have one file named "foo.rb", the command that gets executed is find . -name foo.rb. ("find a file named foo.rb")

It gets even worse if you've multiple files in the current directory (say, "foo.rb" and "bar.rb"). Then the command becomes find . -name foo.rb bar.rb, which will cause an argument error for find.

To prevent the shell from expaning the glob pattern *.rb, you must either quote it (either single or double quotes will do) or escape the asterisk. The below commands have equivalent behavior:

find . -name "*.rb"
find . -name '*.rb'
find . -name \*.rb
share|improve this answer
add comment

Wildcards, Quotes, Back Quotes and Apostrophes in shell commands ( * ? [] " ` ') http://www.codecoffee.com/tipsforlinux/articles/26-2.html I goggled it lol

share|improve this answer
    
You can try man bash and then /QUOTING (the slash starts a search) and read it up in the manpage as well. –  user unknown Apr 14 '12 at 23:03
add comment

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.