Command Line Examples: grep

From PHYSpedia
Jump to: navigation, search

The grep command can be used to

  1. find files that contain a specific string of text
  2. "filter" text in a pipeline to only lines matching (or only lines not matching) a specific string of text

To search a single file for the string "password"


grep "password" file.txt

This will print a list of lines that contain the word password.

To search all files ending in .txt for the string "password"


grep "password" *.txt

This will print a list of lines that contain the word "password", but it will also show the file name that the line was found in.