Linux ~ 查看日志的常用命令總結
1.tail
-n <行數>,顯示文件的尾部n行內容。 -f 循環讀取,常用於查閱正在改變的日志文件。
① tail -f test.log 實時顯示test.log文件里的最尾部的內容,只要test.log更新就可以看到最新的文件內容。
② tail -100f test.log 實時監控100行日志。
③ tail -n 100 test.log 查詢日志尾部最后100行日志內容。
④ tail -n +100 test.log 查詢100行之后所有的日志內容。
2.head
①head -n 100 test.log 查詢日志文件中的頭100行日志。
②head -n -100 test.log 查詢日志文件中除了最后100行的其他內容。
3.grep
①grep "debug" test.log 查詢test.log中所有含有debug關鍵字的記錄
4.more和less
①cat -n test.log | grep "debug" test.log | more 這樣就可以分頁打印了,通過點擊空格鍵翻頁。
5.使用>xxxx.txt將查到的日志保存到文件中。
①cat -n test.log |grep "debug" >debug.txt