command terminal Linux Commands MOC


The grep command searches for text within a given file or output, often with Regular Expressions.

Usage

grep "<search-term>" <file>

grep <options> <Regexp> <file>

$ grep Fla* flag.txt
Here is your Flag:CorbanIsGreat!

Match Control

FlagDescription
-e <pattern>, --regexp=<pattern>Use pattern as regular expression
-f <file>, --file=<file>Takes patterns from file
-i, --ignore-caseIgnores capitalization in given expression
-v, --invert-matchNegates pattern
-w, --word-regexpMatches input text with spaces/punctuation around word
-x, --line-regexpMatches entire line

General Output Control

FlagDescription
-c, --countOutput count only
--color[=WHEN]Colorize (never, always, auto)
-l, --files-with-matchesOutput names of files only
-L, --files-without-matchesOutput names of files without match
-m <NUM>, --max