I can do this:

$ grep 'text' foo/* foo/**/*

but the problem with that is that it expands to list all the files AND directories, so I get a bunch of these errors:

grep: foo/a: Is a directory
grep: foo/bar/b: Is a directory
grep: foo/bar/c: Is a directory
grep: foo/bar/c/d: Is a directory

So my question is, is there a globstar pattern I can use to only match files?

Note that some directories can contain . and some files may not have an extension, so **/*.* doesn't work.

Also, this question is specifically about the ZSH globstar patterns, and not about other solutions, such as:

find foo -type f -exec grep -l "text" {} \;


grep -r 'text' foo

1 Answer 1


You can use **/*(.) to match only plain files or **/*(-.) to match only plain files and symlinks that point to plain files.

Or if you put setopt globstarshort in your .zshrc file, you can use **(.) and **(-.) instead.


  • Perfect answer, thanks! 👍
    – Sarke
    Apr 3, 2021 at 20:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .