"find: paths must precede expression:" How do I specify a recursive search that also finds files in the current directory?

I am having a hard time getting find to look for matches in the current directory as well as its subdirectories.

When I run find *test.c it only gives me the matches in the current directory. (does not look in subdirectories)

If I try find . -name *test.c I would expect the same results, but instead it gives me only matches that are in a subdirectory. When there are files that should match in the working directory, it gives me: find: paths must precede expression: mytest.c

What does this error mean, and how can I get the matches from both the current directory and its subdirectories?


Try putting it in quotes -- you're running into the shell's wildcard expansion, so what you're acually passing to find will look like:

find . -name bobtest.c cattest.c snowtest.c

...causing the syntax error. So try this instead:

find . -name '*test.c'

Note the single quotes around your file expression -- these will stop the shell (bash) expanding your wildcards.


What's happening is that the shell is expanding "*test.c" into a list of files. Try escaping the asterisk as:

find . -name \*test.c

Try putting it in quotes:

find . -name '*test.c'