指定单个文件查找
方法一:cat test.log | grep “关键字”
方法二:grep -i “关键字” ./test.log
关键字查询日志,并显示该条日志的前后n(10)行记录
cat test.log | grep -B10 -A10 “关键字”
从当前目录的所有.log文件中查找内容关键字是“test”文件
find -name ‘.log’ | xargs grep -l “test”
或者
find -name '.log’ exec grep -l ‘test’{}\;
查找日志尾部最后50行的日志
tail -n 50 test.log
查询10行之后的所有日志
tail -n +10 test.log
查询日志文件中的头10行日志
head -n 10 test.log
查询日志中除了最后10行的其他所有日志
head -n -10 test.log
查找指定时间段的日志
sed -n ‘/2020-01-01 13:10:10.294/, /2020-01-01 14:10:10.294/p’ test.log
关键字搜索指定时间段的日志
sed -n ‘/2020-01-01 13:10:10.294/, /2020-01-01 14:10:10.294/p’ test.log | gre