What does the grep command do?

The grep command in Linux is used to search for specific patterns or strings within files or input provided to it. It stands for "Global Regular Expression Print." Here are some key features of the grep command:

  • Pattern Matching: It searches for lines that match a specified pattern, which can be a simple string or a more complex regular expression.
  • Output: By default, grep prints the lines that contain the matching pattern to the standard output.
  • Options: grep supports various options to modify its behavior, such as:
    • -i: Ignore case distinctions.
    • -v: Invert the match, showing lines that do not match the pattern.
    • -r: Recursively search through directories.
    • -n: Show line numbers with output lines.

Example usage:

grep "search_term" filename.txt

This command will search for "search_term" in filename.txt and display any matching lines.

0 Comments

no data
Be the first to share your comment!