Rüdiger
Rüdiger

Reputation: 943

Find a String in all Files with a certain name in Mac Terminal

I am looking for a way to find all "info.plist"-files that contain "iphonesimulator" in my directory and all subdirectories.

I know that I can find all "iphonesimulator" via:

grep -ri "iphonesimulator" .

But that is not everything that I want. Is there a way to also filter for files? I tried with -f but that does not work.

Upvotes: 0

Views: 1473

Answers (1)

Niko
Niko

Reputation: 810

You can use the following:

find <root_directory> -name '<file_matching_pattern>' -exec cat {} \; -exec grep --colour -i 'text_matching_pattern' {} \;

For your particular example:

find / -name info.plist -exec cat {} \; -exec grep --colour -i '*iphonesimulator*' {} \;

or you can just ignore file name pattern and do it like this

Upvotes: 1

Related Questions