grep - Text Search

You can search for text using the grep command .

grep Text FileName

This is a sample of grep.

grep Foo foo.txt

You can specify multiple file names.

grep Text FileName1 FileName2

Search directory recursively

There is a "-r" option that allows you to search directories recursively. All files, including subdirectories, will be searched.

grep -r Text DirectoryName

Case insensitive

There is a case-insensitive "-i" option.

# Both FOO and foo get caught
grep -i foo filename

Use Perl regular expressions

This is an experimental feature of the Linux grep command, but with the "-P" option, you can use Perl regular expressions with grep. increase.

grep -P '^(foo|bar)$' filename

Associated Information