Modifying this control will update this page automatically
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.