The `grep` command stands for Global Regular Expression Print . It is used in Unix-like operating systems to search for specific patterns within files or input streams. It prints lines that match the given pattern.
Syntax:
\[
grep [options] pattern [file]
\]
- pattern : The string or regular expression to search for.
- file : The file(s) in which to search. If no file is specified, `grep` searches the standard input.
Key Options:
- -i : Ignore case (case-insensitive search).
- -r : Search recursively in directories.
- -v : Invert the match (return lines that do not match the pattern).
- -n : Show line numbers along with matching lines.
Example:
To search for the word "error" in a file `log.txt`:
\[
grep "error" log.txt
\]
This will return all lines in the file `log.txt` that contain the word "error".