Linux grep key word search

ASCII文件:more "文件名"|grep "关键字"
Binary文件:more "文件名"|grep -a "关键字"
 
Check path and find file which contains the key words
grep -R <key words> <path>
Example: grep -R '192.168.0.1' /etc
 
Check path and find file which contains the key words, only display the file name
grep -R -l <key words> <path>
Example: grep -R -l '192.168.0.1' /etc
 
Display the before and after lines around the keywords
grep -A<number> -B<number> <keyword> <path>

grep -A2 -B3 'abc' /etc/passwd

Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Linux RHCE Preparation

Snort+barnyard2+Snorby CentOS 6.5_64 Installation