← 返回命令列表

Linux command

egrep 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Search for pattern

egrep "[pattern]" [file.txt]

Search case-insensitive

egrep -i "[pattern]" [file.txt]

Search with line

egrep -n "[pattern]" [file.txt]

Search recursively

egrep -r "[pattern]" [directory]

Search for multiple

egrep "[pattern1]|[pattern2]" [file.txt]

Count matches

egrep -c "[pattern]" [file.txt]

Show only matching

egrep -l "[pattern]" [*.txt]

说明

egrep searches files for lines matching an extended regular expression pattern. It's equivalent to `grep -E` and supports ERE syntax including +, ?, |, and () without escaping. Extended regular expressions are more readable than basic grep patterns for complex matches. Alternation (|), grouping (), and quantifiers work directly without backslashes. egrep is deprecated in favor of `grep -E` but remains widely available for compatibility.

参数

-i
Case-insensitive search.
-n
Show line numbers.
-r, -R
Recursive search.
-l
Show only filenames.
-c
Count matching lines.
-v
Invert match (non-matching lines).
-o
Show only matched parts.
--help
Display help information.

FAQ

What is the egrep command used for?

egrep searches files for lines matching an extended regular expression pattern. It's equivalent to `grep -E` and supports ERE syntax including +, ?, |, and () without escaping. Extended regular expressions are more readable than basic grep patterns for complex matches. Alternation (|), grouping (), and quantifiers work directly without backslashes. egrep is deprecated in favor of `grep -E` but remains widely available for compatibility.

How do I run a basic egrep example?

Run `egrep "[pattern]" [file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i do in egrep?

Case-insensitive search.