find: unknown primary or operator

rob34

Member

Reaction score: 3
Messages: 53

[CMD="u"][/CMD]Tonight I executed a command that I've probably run thousands of times:
Code:
find . -name *.php
And I got a strange, single line response instead of a list of php files:
Code:
find: cron.php: unknown primary or operator
There is a file called cron.php in the working directory. There is nothing special about that file; it's just another php file.

If I move up one directory (from /usr/local/www/drupal7 to /usr/local/www) and execute the same command it runs fine.

The following command runs perfectly from several other directories that I tried, just not from /usr/local/www/drupal7:
Code:
find /usr/local/www/drupal7 -name *.php
This behavior occurred on a FreeBSD 9.0 AMD64 machine. I have a 7.4 AMD64 machine that has the same directory structure and I get a similar error there. Instead of "unknown primary or operator", I get "unknown option."

Has anyone else seen anything like this? Am I doing something wrong?
 

phoenix

Administrator
Staff member
Administrator
Moderator

Reaction score: 1,268
Messages: 4,099

* is expanded by the shell before the command-line is passed to find(1). If there's only 1 item in the directory, then it works. If there's more than one item in the directory, then it fails as the command-line options are no longer correct.

The correct command-line is:
# find . -name '*.php'

You have to escape the * so that find does the expansion internally.
 

pkubaj

Aspiring Daemon

Reaction score: 101
Messages: 555

phoenix said:
* is expanded by the shell before the command-line is passed to find(1). If there's only 1 item in the directory, then it works. If there's more than one item in the directory, then it fails as the command-line options are no longer correct.

The correct command-line is:
# find . -name '*.php'

You have to escape the * so that find does the expansion internally.
I'd like to note that
# find . -name \*.php
also works (for me at least).
 
Top