How to grep files in current dir and all subdirs

I know this question has been asked before but the proposed solutions don't work for me.

I'm trying to find the string "modelInstance.addObservers" in any file (ideally any file with the .js ending, but it's fine without this filter too) in the current directory and all subdirectories. Here's what I tried:

grep -rl "modelInstance.addObserver" .

It behaves as if the statement is incomplete, because it keeps printing blank lines when I hit enter. What is the problem?

I'm on mac.

Here's what it looks like:enter image description here

2

1 Answer

There is nothing wrong: your terminal echoes typed characters when no program is prompting for input; meanwhile grep is running, but not finding any files with the matching string.

It will be a lot faster if you restrict your searches to .js files by using find:

find . -name "*.js" -exec grep -l 'modelInstance\.addObservers' {} \;

Note that I have escaped the . in the search string in order to match only a literal . and not an arbitrary character in that position.

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

You Might Also Like