10、history
可以查看命令歷史記錄,每一條命令前面都會有一個序列號標示。
10.1.1 命令語法:
history [選項]
10.1.2 選項參數
history命令選項參數含義
選項 選項含義
-c 清除命令歷史記錄
-w 讓bash將歷史命令立即從內存寫到.bash_history文件
-a 將目前新增的history歷史命令寫入.bash_history文件
n 顯示最近n個命令歷史記錄,n代表數字
-r 讀取歷史文件的內容,並把它們作爲當前歷史
10.1.2 調用歷史命令
例1,列出目前內存內的所有 history 歷史記錄
[root@localhost~]#history
# 前面省略
1017 man bash
1018 ll
1019 history
1020 history
列出的信息當中,共分兩欄,第一欄爲該命令在這個 shell 當中的代碼, 另一個則是命令本身的內容!至於會顯示多少條命令記錄,則與 HISTSIZE 有關!
例2,列出目前最近的 3 條數據
[root@localhost~]#history 3
1019 history
1020 history
1021 history 3
例3,立刻將目前的數據寫入 histfile 當中
[root@localhost~]#history -w
# 在默認的情況下,會將歷史紀錄寫入 ~/.bash_history 當中!
[root@localhost~]#echo $HISTSIZE
1000