Question:

What is the ‘grep’ command?

Show Hint

The{grep} command is used to search for patterns in files or input streams in Unix-like systems. It prints lines that match a given pattern.
Key options include:
-{-i} for case-insensitive search.
-{-r} to search recursively in directories.
-{-v} to invert the match.
-{-n} to show line numbers with matches.
Updated On: Oct 13, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

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".
Was this answer helpful?
0
0