21

Using find with grep, one can locate files that match a pattern:

# find | grep error
./solr-modifiedSolr4/SolrPhpClient/phpdocs/errors.html
./error_log
./includes/classes/error_log

However, using find alone the first file is not found:

# find . -name error*
./error_log
./includes/classes/error_log

Why doesn't find locate the errors.html file when not used with grep? How is find used to show this file as well?

42

You need to quote your argument error* because the shell expands it. So what you're actually running now is find -name error_log, because that's what the shell can expand it to (there's a file named error_log in your current directory).

find . -name 'error*'

Is the correct invocation for your use case.

  • 12
    an altenative writing is find -name error\* - one key less to press ;) this has the same effect, the * gets passed as an literate asterisk to the find command and is not expanded by your shell – zhenech Nov 11 '12 at 11:14
  • 3
    When having trouble with the shell (how it interprets your command-line and passes all arguments and parameters to the actual command), re-run the command prepending it with the echo command. So, if you'd run echo find . -name error* it would have outputted find . -name error_log – Carlos Campderrós Nov 12 '12 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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