linux查看历史命令history
原文連接:https://blog.csdn.net/gui951753/article/details/79225429
1.可以按一下上\下方向鍵,命令行就會顯示相對于當前命令的上一條或下一條歷史記錄.
2.和方向鍵相同功能的就是組合鍵Ctrl+ p?(前面執行過的命令),Ctrl +n(后面執行過的命令).
2.上面兩個都是相對于當前命令查詢上一條或者下一條命令的歷史記錄.如果搜索命令歷史記錄,
就用Ctrl+ r?組合鍵進入歷史記錄搜尋狀態,然后,鍵盤每按一個字母,當前命令行就會搜索出命令歷史記錄.
?
1. history作用
?
linux的history命令的作用是,記錄執行過的命令。
用法:
history [n] ?n為數字,列出最近的n條命令
-c ?將目前shell中的所有history命令消除
history [-raw] histfiles
-a 將目前新增的命令寫入histfiles, 默認寫入~/.bash_history
-r ?將histfiles內容讀入到目前shell的history記憶中
-w 將目前history記憶的內容寫入到histfiles
shell > history34 14-10-28 16:19:24 ll35 14-10-28 16:19:26 vim test36 14-10-28 16:19:33 ll37 14-10-28 16:19:34 ll
?
?
使用! 執行歷史命令。
! number 執行第幾條命令
! command 從最近的命令查到以command開頭的命令執行
!! 執行上一條
shell > !1046 history 31045 14-11-02 16:22:38 head ~/.bash_history 1046 14-11-02 16:35:37 history 31047 14-11-02 16:35:48 history 3 shell > !! history 31046 14-11-02 16:35:37 history 31047 14-11-02 16:35:48 history 31048 14-11-02 16:35:52 history 3 shell > !head head ~/.bash_history #1414484377 cd update/ #1414484377
?
2. history配置修改
?
history記錄的行數
shell > echo $HISTSIZE 1000 shell >默認記錄1000行
配置文件在/etc/profile中修改
HISTSIZE=1000 export HISTSIZE歷史命令文件記錄在 ~/.bash_history中
?
想要讓linux的history命令顯示時間,history是默認不帶時間,
在/etc/profile 中增加
export HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "查看.bash_history
shell > head ~/.bash_history #1414484377 cd update/ #1414484377 ll #1414484388 vim address #1414484439 ll #1414484440 ll shell >3. 同一賬號同時多次登錄寫入history
?
普通情況下, 當以bash登錄系統時,系統會從~/.bash_history讀取以前運行的命令
當注銷時,把最新的1000(HISTSIZE)條命令更新到~/.bash_history文件中。
也可以使用history -w強制立刻寫入,僅保留最新的。
?
當同一賬號,同時登錄多個bash時,只有最后一個退出的會寫入bash_history,其他的都被覆蓋了。
?
4. Ctrl+r 反向查詢歷史命令
?
使用Ctrl+r反向查詢歷史命令,將匹配的最新一條顯示出來
如果還想繼續向上查詢,繼續按Ctrl+r
shell > history 3 1048 14-11-02 16:35:52 history 31049 14-11-02 16:36:11 head ~/.bash_history 1050 14-11-02 16:41:05 history 3 (reverse-i-search)`his': head ~/.bash_history總結
以上是生活随笔為你收集整理的linux查看历史命令history的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 425 Failed to establ
- 下一篇: 科学计数法(PAT)