查看日志 前 n行:
1、 cat 文件名 | head -n 數量
demo
cat test.log | head -n 100 # 查看test.log前100行
查看日志 尾 n行:
2、 cat 文件名 | tail -n 數量
demo
cat test.log |tail -n 100 # 查看test.log倒數100行
3、根據 關鍵詞 查看日志 並返回關鍵詞所在行:
方法一:cat 路徑/文件名 | grep 關鍵詞
demo
cat test.log | grep "http" # 返回test.log中包含http的所有行
方法二:grep -i 關鍵詞 路徑/文件名 (與方法一效果相同,不同寫法而已)
demo:
grep -i "http" ./test.log # 返回test.log中包含http的所有行