Linux常用查詢文件命令
cat
cat 命令用於連接文件並打印到標準輸出設備上。
cat [-AbeEnstTuv] [–help] [–version] fileName
實例:
- 把 textfile1 的文檔內容加上行號後輸入 textfile2 這個文檔裏:
cat -n textfile1 > textfile2
vim
詳細查看菜鳥教程: https://www.runoob.com/linux/linux-vim.html
tail
實例
- 要顯示 notes.log 文件的最後 10 行,請輸入以下命令:
tail notes.log
- 要跟蹤名爲 notes.log 的文件的增長情況,請輸入以下命令:
tail -f notes.log
- 顯示文件 notes.log 的內容,從第 20 行至文件末尾:
tail +20 notes.log
- 顯示文件 notes.log 的最後 10 個字符:
tail -c 10 notes.log
less
less [參數] 文件
場景
需要查詢Exception
的那些行
grep -i Exception [fileName]
這個時候查到了帶有Exception的內容,如果有更多的內容怎麼辦?
- 先定位到行號
grep -n Exception [fileName]
2.我們可以看到輸出了很多行號,根絕這個行號查看上下100行的數據就行了
sed -n 'start , endp' [fileName]