The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
  

grep - Searching for Strings in Files





The grep command is a powerful tool in Unix-like systems used for searching and matching patterns in text files. The name grep stands for "Global Regular Expression Print." It's capable of efficient text searching and supports regular expressions.

The basic syntax of grep is grep [OPTIONS] PATTERN [FILE...], where "PATTERN" is the text or regular expression you want to search for.

Some commonly used options include:

Examples
$ man tar | grep -n 'GNU' ←Search for lines with 'GNU' in the 'tar' man page and show line numbers
12:     GNU `tar' saves many files together into a single tape or disk archive
88:     handle new GNU-format incremental backup
$$ seq 1 10000 | grep '789' ← # Search for lines containing '789
789
1789
2789

For more grep examples, explanations, and options, you can refer to the provided link.