Linux command
fgrep 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Search for literal
fgrep "[search string]" [file.txt]
Search multiple files
fgrep "[pattern]" [file1.txt] [file2.txt]
Case insensitive search
fgrep -i "[pattern]" [file.txt]
Show line numbers
fgrep -n "[pattern]" [file.txt]
Recursive search
fgrep -r "[pattern]" [directory]
说明
fgrep searches for fixed strings rather than regular expressions. It's equivalent to grep -F and is faster when searching for literal text without regex metacharacters. The tool treats the pattern as a plain string, so characters like ., *, and [ have no special meaning. This makes it ideal for searching log files, code, or any text containing regex metacharacters. fgrep is particularly useful when the search pattern comes from user input or variables that might contain special characters.
参数
- -i, --ignore-case
- Case insensitive matching.
- -n, --line-number
- Show line numbers.
- -r, --recursive
- Search directories recursively.
- -l, --files-with-matches
- Show only filenames.
- -c, --count
- Count matching lines.
- -v, --invert-match
- Show non-matching lines.
- --help
- Display help information.
FAQ
What is the fgrep command used for?
fgrep searches for fixed strings rather than regular expressions. It's equivalent to grep -F and is faster when searching for literal text without regex metacharacters. The tool treats the pattern as a plain string, so characters like ., *, and [ have no special meaning. This makes it ideal for searching log files, code, or any text containing regex metacharacters. fgrep is particularly useful when the search pattern comes from user input or variables that might contain special characters.
How do I run a basic fgrep example?
Run `fgrep "[search string]" [file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -i, --ignore-case do in fgrep?
Case insensitive matching.