Linux environment: summary of several commands for viewing logs

1.tail specifies the number of rows

tail -200f catalina.out
显示 catalina.out日志文件 的最后 200 行的内容

2.grep shows key lines

grep date catalina.out
把关键字所在行给你显示出来, 并高亮关键字

3.grep query keywords with spaces

	grep '调用接口 club' catalina.out
	多个单词并带有空格, 使用 '' 单引号修饰

4.grep show log context

grep-5 date catalina.out
数字 5 就表示前后 5 行, 如果是 -10 就表示前后 10 行

5.grep displays the log context line number

grep-5 -n date catalina.out
这样关键行的前 5 行和后 5 行的行号也会显示出来.

6. Pipe symbol | combined tail and grep commands

(1)tail catalina.out | grep date 
	把 tail 出来的最后 10 行的内容交给 grep 去过滤, 找出含有 date 关键字的行
	
(2)tail -n 50 catalina.out | grep -10 date
	在最后 50 行中去搜索 date关键字,并显示关键字所在行及上下各 10 行的内容

Guess you like

Origin blog.csdn.net/weixin_43945983/article/details/109571105