废话不多说,直接开始,今天由于elk挂了,导致测试环境服务器看不了日志,下面分享给大家几个常用的查看日志的小方法。
tail 的使用方法
描述:Print the last 10 lines of each FILE to standard output 。默认输出文件最新的10行写到标准输出。
命令: tail [OPTION]... [FILE]...
例子:tail -f elasticsearch.log 查看elasticsearch.log 最新的日志
参数
-n:-n<行数> 显示文件的尾部 n 行内容
tail -10 elasticsearch.log 显示最新10行
-f: -f 循环读取 ,使用-f参数后,当文件有追加时候,会持续显示。
-f 和 -n 组合使用
语法: tail -50f elasticsearch.log , 会显示最新的50行,并且,如果有新的内容会持续显示。
同时查看多个文件
语法:tail fileName1 fileName2
例子:tail test.txt nginx.conf
tail 和 grep 组合使用
查看nginx.conf 文件里 server 关键字,每个关键字 后面的20行; -A 表示after
tail -40f nginx.conf |grep server -A 20