sh 在文件中搜索

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 在文件中搜索相关的知识,希望对你有一定的参考价值。

# Search a fixed word or sentence (substring) in a file
fgrep "word or sentence" path/to/file
fgrep "importat" production.log

# Search some pattern in a file
grep "pattern" path/to/file
grep "alias= b.*" ~/.bashrc

# Search on a gz and zip files
zgrep "pattern" path/to/file.gz
zipgrep "pattern" path/to/file.zip

# Show context lines after and before the matches; works for all grep commands
grep "pattern" -A<after-lines> -B<before-lines> path/to/file
grep "invoices/" -A3 -B1 log/production.log

# Search in a folder (to show all matches, omit -l parameter); works for all grep commands
grep -rl "pattern" path/to/folder
grep -rl "my-secret-password" /home/user

以上是关于sh 在文件中搜索的主要内容,如果未能解决你的问题,请参考以下文章

sh 搜索文本文件中的字符串并替换它们

sh 如何使用grep和ack递归搜索文件夹中的字符串

sh [sh - 递归搜索]递归移动文件#macOS #nix #Bash

sh 搜索所有文件夹

sh 搜索所有文件

sh 搜索文件以查找特定内容