linux 常用檢視日誌命令
1、tail 檢視文字檔案的尾部
tail -f alert_monitor.log //實時檢視alert_monitor.log檔案 日誌
tail -n 100 alert_monitor.log //查詢日誌尾部最後100行的日誌
tail -n +100 alert_monitor.log // 查詢100行之後的所有日誌
2、cat 檢視檔案
cat -n alert_monitor.log
cat -n alert_monitor.log | tail -n +100 | head -n 20 //查詢100行之後的日誌,且在100行之後裡再查前20條日誌
3、head 檢視文字檔案的開頭部分
head -n 10 alert_monitor.log //查詢日誌檔案中的頭10行日誌
head -n -10 alert_monitor.log //查詢日誌檔案除了最後10行的其他所有日誌
4、sed 管道命令
sed -n '/2020-04-17 16:17:20/,/2020-04-17 16:20:36/p' alert_monitor.log //檢視時間段日誌
sed -n '100,200p' alert_monitor.log //檢視100行-200行日誌
5、grep 文字搜尋
grep fuju alert_monitor.log //搜尋檔案中 fuju
cat -n alert_monitor.log | grep "ERROR" //查詢關鍵字ERROR的日誌
6、more/less 日誌特別多,分頁檢視
catc -n alert_monitor.log | grep "debug" | more 分頁列印了,通過點選空格鍵翻頁
(more與less區別 less更強大,可在多個終端使用,支援上下鍵前後翻閱)
原文連結:https://blog.csdn.net/weixin_45129277/article/details/124453782