[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Strange issue with `find' command



On 02/08/14 08:41, Rodolfo Medina wrote:
Searching in internet, I've found the solution but not te explanation of the
following error message:

  find: paths must precede expression:

that the `find' command sometimes produces and sometimes not when used with the
`*' character, e.g. to search for `*.pdf'.  The solution consists in quoting
the argument: '*.pdf'.  But it seems to remain obscure when the error is
generated and when and why not.  Please, any idea?


Shell expansion of the "*" character.

If you use *.pdf the shell will try and match it against entries in the current directory.

If there are no matching entries it will leave it as *.pdf.

If there is one matching entry (say "test.pdf") the shell will substitute it so find looks for test.pdf.

If there is more than one matching entry, the shell will expand it to all of them and you get too many parameters. Say we have test1.pdf and test2.pdf.

  find . -name *.pdf

will expand out to

  find . -name test1.pdf test2.pdf

and there you get your error. But

  find . -name "test1.pdf"

will remain unchanged as the shell won't try and expand the quoted values.


--
Dom


Reply to: