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" {} \; 

or

grep -r 'text' foo 

1 Answer

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.

Documentation:

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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