[root@linux ~]# history [n]
[root@linux ~]# history [-c]
[root@linux ~]# history [-raw] histfiles
選項:
n :數字,『列出最近的 n 筆命令列表』。
-c :將目前的 shell 中所有 history 內容全部消除
-a :將目前新增的 history 指令新增入 histfiles 中,若沒有加 histfiles ,
則預設寫入 ~/.bash_history
-r :將 histfiles 的內容讀到目前這個 shell 的 history 記憶中;
-w :將目前的 history 記憶內容寫入 histfiles 中,histfiles 內容會被覆蓋。
#範例:
#範例一:列出目前記憶體內的所有 history 記憶
[root@linux ~]# history
# 前面省略
1017 man bash
1018 ll
1019 history
1020 history
# 列出的資訊當中,共分兩欄,第一欄為該指令在這個 shell 當中的代碼,
# 另一個則是指令本身的內容。至於會秀出幾筆指令記錄,則與 HISTSIZE 有關。
#範例二:列出目前最近的 3 筆資料
[root@linux ~]# history 3
1019 history
1020 history
1021 history 3
#範例三:立刻將目前的資料寫入 histfile 當中
[root@linux ~]# history -w
# 在預設的情況下,會將歷史紀錄寫入 ~/.bash_history 當中。
[root@linux ~]# echo $HISTSIZE
1000
HISTSIZE=1000,這次登入主機共下達過 100 次指令,『登出時,系統就會將 101~1100 這總共 1000 筆歷史命令更新到 ~/.bash_history 當中。』
[root@linux ~]# !number [root@linux ~]# !command [root@linux ~]# !! 參數: number :執行第幾筆指令; command :由最近的指令向前搜尋『指令串開頭為 command』的那個指令,並執行; !! :就是執行上一個指令(相當於按↑按鍵後,按 Enter) #範例: [root@linux ~]# history 66 man rm 67 alias 68 man history 69 history [root@linux ~]# !66 %*<==執行第 66 筆指令*) [root@linux ~]# !! %*<==執行上一個指令,本例中亦即 !66 *) [root@linux ~]# !al %*<==執行最近以 al 為開頭的指令(上頭列出的第 67 個)*)
$HISTSIZE
~/.bash_history