Modifying this control will update this page automatically
![](https://help.apple.com/assets/63FFD63D71728623E706DB4F/63FFD63E71728623E706DB56/en_US/20f5edbfdfa0bd8ad4c4c6452e5b6761.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.