[root@localhost ~]# ls /root/.bash_history /root/.bash_history [root@localhost ~]# cat !$ cat /root/.bash_history init 0 ping www.baidu.com dhclient ping www.baidu.com yum install -y net-tools 等等等
[root@localhost ~]# history 1 init 0 2 ping www.baidu.com 3 dhclient 4 ping www.baidu.com 5 yum install -y net-tools 6 ifconfig
history命令vim
[root@localhost ~]# echo $HISTSIZE 1000 [root@localhost ~]#
history -c //把當前內存裏面命令歷史給清空bash
[root@localhost ~]# history -c [root@localhost ~]# history 1 history
但不會清空 .bash_history 配置文件,僅僅是把歷史命令給清空
在敲完命令後,直接到配置文件中查看,會發現其中並無存在 這是由於僅存在內存中,只有在退出終端的時候,纔可以保存到配置文件中去ide
HISTSIZE=5000
[root@localhost ~]# vim /etc/profile //在裏面編輯文件,改變參數 改變參數後,能夠重啓終端,或者source /etc/profile,發現參數生效 [root@localhost ~]# source !$ //執行命令後,會發現HISTSIZE值變化了 source /etc/profile [root@localhost ~]# echo $HISTSIZE 5000
[root@localhost ~]# history 1 history 2 vim /etc/profile 3 yum provides "/*/vim" 4 yum install -y vim-enhanced 5 vim /etc/profile 6 source /etc/profile 7 echo $HISTSIZE 8 HISTIMEFORMAT="%Y/%m/%d %H:%M:%S" 9 history [root@localhost ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" [root@localhost ~]# history 1 2017/11/15 23:25:28history 2 2017/11/15 23:35:08vim /etc/profile 3 2017/11/15 23:35:29yum provides "/*/vim" 4 2017/11/15 23:53:58yum install -y vim-enhanced 5 2017/11/15 23:59:04vim /etc/profile 6 2017/11/16 00:07:14source /etc/profile 7 2017/11/16 00:07:31echo $HISTSIZE 8 2017/11/16 00:13:45history 9 2017/11/16 00:14:49HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" 10 2017/11/16 00:14:51history 11 [root@localhost ~]# echo $HISTTIMEFORMAT %Y/%m/%d %H:%M:%S
這個環境變量僅僅在當前窗口下的終端生效,在打開另外一個終端的時候,就會顯示空的 也就是說,系統默認這個環境變量是不存在的
[root@hf-01 ~]# vim /etc/profile 進入配置文件中,在變量HISTSIZE下放入 HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" 而後 :wq 保存退出 [root@hf-01 ~]# source !$ source /etc/profile
[root@hf-01 ~]# chattr +a ~/.bash_history [root@hf-01 ~]#
在運行不少命令後,未正常退出(exit或logout正常退出),直接關閉終端,那剛剛敲的命令就不會完整的保存到 .bash_history 中去code