I'd like to find all files that contain a certain string of text. How would you do that in the Terminal?
grep -r 'text goes here' path_goes_here
mdfind "text goes here" mdfind -onlyin /home/user/Desktop -live "live update"
don't forget to look at:
- Through Ack
brew install ack
ack "text goes here"
- Through find
find . |grep "text goes here"
- Through grep
grep -RnslI "text goes here"
Ignacio's Answer is great and helped me find the files containing certain text. The only issue I was facing was that when running this command all the files would be listed, including one where the pattern did not show up.
No such file or directory This is what I see alongside files that do not contain the pattern.
If instead you add
-s to the command, as in:
grep -lr "text pattern" ./ -s ;
grep -lr "text pattern" [PATH DIRECTORY] -s is used, it will only show you which files contain the pattern.
grep -nr "text pattern" ./ -s ;
grep -nr "text pattern" [PATH OF DIRECTORY] -s command is used it prints the file plus the line number, and occurrence of the pattern.
Please correct me if my understanding is wrong.