The grep Command

The grep command is so beloved by Linux users that it has its own t-shirts. The grep command finds files that have specified contents and outputs each line that it finds. The general format for the grep command is:

grep options pattern files
				

where:

  • pattern specifies the text string to search for. pattern can be a literal string, such as abc or xxx. pattern can also be a regular expression, a pattern to be matched, such as any uppercase character or any word that begins with Q. Regular expressions are discussed in Appendix A.

  • files specifies the files to search for the string. files can specify filenames (using wildcards if needed) or a directory.

For example, the following is a simple grep command with its output:

					grep "Mary ...

Get Spring Into Linux® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.