I was using

find -iname *prib*

and getting only one result "./prib09jack.pdf" with

find -iname "*prib*" 

I get many more results that I was looking for such as


and many more, but why did it matter that the quotation marks were around "prib"?


  • Did you launch the command from the same directory and got different answers? What was the whole find command structure you used as there are many options which affect the outcome.
    – dtlussier
    Aug 26 '10 at 16:27
  • I was in the same directory for each use changing only the quotations around the search string.
    – Vass
    Aug 26 '10 at 16:37

If there is a file (or files) matching *prib* in the current directory when the find command is run, the shell will expand the wildcard to match the file name(s) first before handing the arguments to find, and result in a different command being run than the user expects.

For example,

$ ls foo*

$ find -iname foo*

$ find -iname "foo*"

In short, Quotes delay wildcard interpretation for the find command to perform. Lack of quotes expands immediately.

  • 1
    wow, that was deep. I can't say that I completely understood it. So should I always be using the quotes in similar situations? What you said sounded like if it encounters a string matching a form of the wildcard further searches follow this initial wildcard expansion. And that the quotes stop this from happening. (if Im not mistaken the man page says nothing to avoid such a mistake).
    – Vass
    Aug 26 '10 at 16:55
  • 3
    You'd find it explained in the bash man page, not the find man page, because quoting is handled by the shell. Basically (to repeat what kmarsh said), if you use *prib* without quotes, bash looks for files in the current directory with names matching that pattern and replaces *prib* with the names of the files before invoking find. If you use quotes, bash leaves the *prib* alone.
    – David Z
    Aug 26 '10 at 17:02
  • 2
    @Vass: You can use echo *prib* and such to see what bash does to the arguments before it passes them to the command. echo itself just prints it's arguments unchanged, so it's output tells you to what bash expanded the *prib*.
    – sth
    Aug 26 '10 at 17:37
  • 1
    @sth zaw. Thanks, alot. that was eye opening. Thanks alot for bothering to tell me this. Its like there is a whole other dimension to the command line that I was unaware of.
    – Vass
    Aug 26 '10 at 20:38
  • @David, thanks for the elaboration, and @Vass, glad to help and thanks for the accepted answer. @sth good point, I also use echo when I want to see what will happen to wildcard expansion.
    – kmarsh
    Aug 27 '10 at 13:27

The issue is that your shell is expanding the wildcard *'s before handing them to find. You want find to get them, so you need to escape them. The quotes do that, or you could do

find -iname \*iprib\*

and it would work as well. The key thing is, you want the wildcards to make it to find uninterpreted by anything else along the way (like your shell).

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.