1.cat
查看log.log前200行
cat log.log | head -n 200
查看test.log倒数200行
cat test.log | tail -n 200
查看test.log中包含http的所有行
cat test.log | grep "http"
查看test.log中包含http的所有行,并显示前后行
cat -n test.log | grep -C 5 “http” (匹配到的前后5行)
cat -n test.log | grep -B 5 “http” (前5行)
cat -n test.log | grep -A 5 “http” (后5行)
2.grep
查看test.log中包含http的所有行(-i忽略大小写)
grep -i "http" ./test.log
查询关键字出现的次数
grep -o "待统计字符串" xxx.log | wc -l
3.tail
实时日志-关键字查询
tail -f test.log | grep "关键字"
查询最新10 条日志
tail -fn 10 test.log
4.sed
SED 查看某时间段日志
sed -n '/2022-06-02 13:10:30/,/2022-06-02 13:10:40/p' test.log
某时间端日志输出到指定文件中
sed -n '/2022-06-02 13:10:30/,/2022-06-02 13:10:40/p' test.log > test20220602.log