history命令詳解

一、manual說明
Display or manipulate the history list
顯示或操做命令歷史列表
二、概念區分
history list是在內存緩存中的,history file就是在硬盤中的。history list針對當前會話生效。history file 則針對全部會話都生效。當登陸系統系統時,系統就會自動將history list中,當退出系統時,history list中的命令就會自動寫入到history file中去。
~/.bash_history 歷史列表的默認保存位置
~/.bash_profile 當前用戶的環境變量的設置位置
/etc/profile 系統環境變量的默認設置位置
關於HISTORY的變量:
HISTSIZE 命令歷史記錄的條數
HISTFILE 指定歷史文件,默認爲~/.bash_history
HISTFILESIZE: 命令歷史文件記錄歷史的條數
HISTTIMEFORMAT: HISTTIMEFORMAT=「%F%T」 顯示時間
history用法:
history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
Display the history list with line numbers, prefixing each modified entry with a `'. An argument of N lists only the last N entries
顯示帶有行號的歷史記錄列表,並在每一個修改前加上前綴
帶有「
」的條目。N的參數只列出最後的N個元素。
Options:
-c: clear the history list by deleting all of the entries
經過刪除全部條目來清除歷史記錄列表
history命令詳解
-d offset: delete the history entry at offset OFFSET
在偏移位置刪除歷史記錄項(就是刪除指定數字的歷史條目)
history命令詳解
-a: append history lines from this session to the history file
將此會話的歷史記錄行追家到歷史記錄文件
history命令詳解
-n: read all history lines not already read from the history file 。
讀取還沒有從歷史文件中讀取的全部歷史記錄行
history命令詳解
-r: read the history file and append the contents to the history list
讀取歷史文件而後追加到歷史記錄文件中
history命令詳解
-w: write the current history to the history file and append them to the history list
將當前歷史寫入到歷史文件中,同時將他們追加到歷史列表中。
history命令詳解
-p: perform history expansion on each AGR and dispay the result without storing it in the history list
對每一個參數執行歷史擴展並顯示結果,而不將其存儲在歷史列表中
history命令詳解
-s: append the ARGs to the history list as a single entry
添加全部ARGs做爲單獨的條目到歷史記錄條目中。
history命令詳解緩存

其餘比較經常使用的用法:
(一):查看歷史命令
history #顯示全部歷史命令’
history 10 #顯示最近的10條命令
(二)查看默認歷史命令條數:
echo $HISTSIZE
這個環境變量定義在/etc/profile中
(三)命令從新調用
ls !407 #從新調用歷史命令中的正數第407個命令
ls !-4 #從新調用歷史中的倒數第4條命令
歷史命令分兩部分存放: .bash_history 和內存中
正常退出時,內存中的歷史命令會存儲到.bash_history中
(四)執行前面倒數第一個以shut開頭的命令
!shut
(五)執行前面一個包含go的命令
!?go
(六)執行剛剛執行過的命令
一、上下鍵翻
二、!-1
(七)搜索執行過的命令
history命令詳解bash

相關文章
相關標籤/搜索