tail 命令可用于查看文件的內容,有一個常用的參數 -f 常用于查閱正在改變的日志文件。
tail -f filename 會把 filename 文件里的最尾部的內容顯示在屏幕上,并且不斷刷新,只要 filename 更新就可以看到最新的文件內容。
命令格式:
tail [參數] [文件]
參數:
實例
要顯示 notes.log 文件的最后 10 行,請輸入以下命令:
tail notes.log # 默認顯示最后 10 行
要跟蹤名為 notes.log 的文件的增長情況,請輸入以下命令:
tail -f notes.log
此命令顯示 notes.log 文件的最后 10 行。當將某些行添加至 notes.log 文件時,tail 命令會繼續顯示這些行。 顯示一直繼續,直到您按下(Ctrl-C)組合鍵停止顯示。
顯示文件 notes.log 的內容,從第 20 行至文件末尾:
tail -n +20 notes.log
顯示文件 notes.log 的最后 10 個字符:
tail -c 10 notes.log