Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 41 down vote accepted

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.

share|improve this answer
    
Thank you Dennis! I knew that it had to be simple! –  dotancohen Nov 11 '12 at 10:24
11  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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