在 Linux 終端下,為了方便檢查操作中可能出現的錯誤、並避免螢幕滾動造成的遺漏,我們可以把操作日誌記錄下來。常用工具有 screen、script 與 tee。
> screen -L>(這裡進行你的操作)> exit
結束後會產生類似 screenlog.0 的檔案,用 more screenlog.0 即可回看操作、找出可能的問題。
> script>(我們的操作)> exit
會產生一個名為 typescript 的檔案,用 more typescript 查看操作內容。
這個指令能讀取終端輸入並同時輸出到螢幕與檔案,很適合記錄 make 等指令的大量輸出:
> make 2>&1 | tee make.log
當然也可以直接重定向:> make > make.log。其中 2>&1 是用來一併記錄錯誤日誌。
若想過濾掉控制符號,可以搭配 col 指令:
$ cat screenlog.0 | col -b > screenlog
或$ cat typescript | col -b > scriptlog