歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> 記錄linux操作命令日志

記錄linux操作命令日志

日期:2017/3/2 16:45:48   编辑:Linux服務器

在linux終端下,為方便檢查操作中可能出現的錯誤,以及避免屏幕滾屏的限制,我們可以把操作日志記錄下來。常用的工具有screen,script,以及tee等。

1. screen — screen manager with VT100/ANSI terminal emulatio

> screen -L
>這裡是我們的操作
> exit
結束後會生成一個類似這樣的文件名: screenlog.0
> more screenlog.0
這樣可以查看你剛才進行的操作,發現可能存在的問題

2. script — make typescript of terminal session

> script
>我們的操作
> exit
生成一個這樣的文件:typescript
> more typescript
這裡查看我們進行的操作

3. tee – read from standard input and write to standard output and files

這個命令可以讀取終端輸入輸出到終端或者文件中,有時候可以用來記錄make等命令可能產生的輸出到終端的大量內容輸出到文件中去。這樣可以方便記錄這些命令的日志。

> make 2>&1 | tee make.log
當然,我們也可以直接重定向到一個文件中
> make > make.log

PS: 2>&1是為了記錄錯誤日志
if you want to filter the control symbols, try to use the “col” command like this:

$ cat screenlog.0 | col -b > screenlog

or

$ cat typescript | col -b > scriptlog

Copyright © Linux教程網 All Rights Reserved