0
点赞
收藏
分享

微信扫一扫

linux 日志中查找关键字

醉东枫 2022-03-22 阅读 77
java后端

linux 日志中查找关键字

1、查看日志前 n行

cat 文件名 | head -n 数量

demo:

cat test.log | head -n 200  # 查看test.log前200行

2、查看日志尾 n行

cat 文件名 | tail -n 数量

demo:

cat test.log | tail -n 200  # 查看test.log倒数200行

3、根据关键词查看日志 并返回关键词所在行

方法一:cat 路径/文件名 | grep 关键词

demo:

cat test.log | grep “http”  # 返回test.log中包含http的所有行

方法二:grep -i 关键词路径/文件名 (与方法一效果相同,不同写法而已)

demo:

grep -i -a “http” ./test.log  # 返回test.log中包含http的所有行(-i忽略大小写)

  • -a, --text equivalent to --binary-files=text,即让二进制文件等价于文本。
举报

相关推荐

continue关键字break关键字

0 条评论