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.

I was under the impression that the following command will search for, and list all Java files starting from the current directory and recursing down.

However, if I have a Java file in the root of my home directory, it lists that one, and then stops.

Is find supposed to stop at the first match, even with a wildcard? I guess I have a misconception about the usage. Thanks for any enlightenment.

find . -name *.java
share|improve this question

1 Answer 1

up vote 1 down vote accepted

The wildcard pattern *.java is expanded by your shell before it is passed to the find command. If you have a single file foo.java in the current directory, then the shell executes the command find . -name foo.java. If you have two files bar.java and foo.java, the command find . -name bar.java foo.java is executed and find complains of a syntax error. If there is no matching file in the current directory, then the shell leaves the pattern unexpanded, so find . -name *.java is executed as you desire.

To tell the shell not to expand the pattern, so that it is always passed as-is to find, quote it:

find . -name '*.java'
find . -name "*.java"
find . -name \*.java
share|improve this answer
    
Splendid! Thanks. Shall "accept" in 3 minute. –  EdgeCase Jan 20 '13 at 14:51

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.