linux tail 命令查看日志

#输出文件末尾行(默认10行),当文件有追加时,会输出后续添加的行,不会中断输出,除非ctrl+c中断  
#-f 即 --follow=file.log
tail -f file.log                               

#输出文件末尾包含关键字的行,当文件有追加时,会输出后续添加的行,不会中断输出,除非ctrl+c中断  
#-f 即 --follow=file.log
tail -f file.log | grep "关键字"                

#输出文件的后100行中包含关键字的行(-n 100 即 --lines=100)  
tail -n 100 file.log | grep "关键字"            

#输出文件的后100行中包含关键字的行和该行的后10行    
tail -n 100 file.log | grep "关键字" -A10      

 #输出文件的后100行中包含关键字的行和该行的前10行     
tail -n 100 file.log | grep "关键字" -B10      

#输出文件的后100行中包含关键字的行和该行的前后10行    
tail -n 100 file.log | grep "关键字" -B10 -A10  







原创文章 21 获赞 13 访问量 8398

猜你喜欢

转载自blog.csdn.net/iteye_19045/article/details/99745319