Modifying this control will update this page automatically
![](https://help.apple.com/assets/5D92A6940946227D4301035B/5D92A6A50946227D43010362/en_US/31d7054c3bcf00abcba6dd75555bcff0.png)
Search for text in a file using Terminal on Mac
To locate a string within a file, use the grep
tool.
The grep
tool searches the named input files for lines containing a match to the given pattern. By default, grep
prints the matching lines.
To search for a unique string in a file:
% grep search_string filename
Replace search_string with the string to search for, and replace filename with the name of the file whose contents you want to search.