Modifying this control will update this page automatically
![](https://help.apple.com/assets/58C4E5B4680CE2040551BA60/58C4E5B6680CE2040551BA69/en_US/31d7054c3bcf00abcba6dd75555bcff0.png)
Search for text in a file using Terminal
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.