Search one or more files for lines that match a regular expression (a search pattern).


grep [options] pattern files


-N (where N is a number) displays N lines around the line containing pattern.

-c shows the number of lines that contain the search pattern.

-f file reads options from a specified file.

-i ignores case.

-l displays the filenames that contain pattern.

-n displays a line number next to lines that contain pattern.

-q returns a status code but does not display any output.

-v displays the lines that do not contain pattern.

-w matches only whole words.


The grep command searches the specified files for a pattern. The pattern is a regular expression that has its own rules. Typically, you use grep to search for a specific sequence of characters in one or more text files.