find . -name *.rb
doesn't work on my ubuntu
I have to do
find . -name "*.rb"
to get it to work.
Why is that?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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