1、指令别名設定:alias、unalias(僅在本次終端下可以使用,關閉後需要重新設定)
alias的定義規則與變量定義規則幾乎相同 $ 别名=‘指令 參數 選項 ’
檢視目前系統使用别名情況:$ alias
2、曆史指令
指令:$ history [-raw] histfiles
選項與參數:
n :數字,意思是『要列出最近的 n 筆指令行表』的意思!
-c :将目前的 shell 中的所有 history 内容全部消除
-a :将目前新增的 history 指令新增入 histfiles 中,若沒有加 histfiles , 則預設寫入 ~/.bash_history
-r :将 histfiles 的内容讀到目前這個 shell 的 history 記憶中;
-w :将目前的 history 記憶内容寫入 histfiles 中!
範例一:列出目前記憶體内的所有 history 記憶
[[email protected] ~]$ history
# 前面省略
1017 man bash
1018 ll
1019 history
1020 history
# 列出的資訊當中,共分兩欄,第一欄為該指令在這個 shell 當中的代碼,
# 另一個則是指令本身的内容喔!至于會秀出幾筆指令記錄,則與 HISTSIZE 有關!
範例二:列出目前最近的 3 筆資料
[[email protected] ~]$ history 3
1019 history
1020 history
1021 history 3
# 在預設的情況下,會将曆史紀錄寫入 ~/.bash_history 當中!
[[email protected] ~]$ echo ${HISTSIZE}
1000
HISTSIZE記錄存儲的曆史指令條數,使用echo指令檢視其大小。
[email protected] ~]$ !number
[[email protected] ~]$ !command
[[email protected] ~]$ !!
選項與參數:
number :執行第幾筆指令的意思;
command :由最近的指令向前搜尋『指令串開頭為 command』的那個指令,并執行;
!! :就是執行上一個指令(相當于按↑按鍵後,按 Enter)
同一賬号同時多次登入後,系統隻更新記錄最後登出的bash(終端)history,實質對每個bash都有記錄,但最終被最後一個 bash所覆寫。對于history,其無法記錄時間,是以存在一定的缺陷。