I am trying to find all my GRAPHML files under the current directory in bash. So I ran the following command:

find . -name *.graphml

And I get the error message:

find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

What is wrong with the command above? The strange thing is that it works fine for other regexps.

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

Always enclose the pattern in quotes (e.g. *.graphml in your case). Otherwise it will be expanded by the shell before the find command. This means that find does not get a literal *graphml passed, but rather what the shell expands *.graphml to.

Therefore:

find . -name "*.graphml*"

See:

  • man find which says: "Don't forget to enclose the pattern in quotes in order to protect it from expansion by the shell."
  • A little more about Quoting from the Advanced Bash Scripting Guide.
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.