強制history不記住敏感命令的方法

     有時候爲了服務器安全,防止別人窺探咱們輸入的命令,咱們能夠清空歷史記錄,而更多的時候,咱們選擇的是在輸入特殊命令時候,強制歷史記錄不記住該命令。實驗方法:先執行export HISTCONTROL=ignorespace 命令,而後依次輸出ls -tra  ,pwd和service mysqld start 的命令,當執行第三個命令的時候,咱們選擇不記住該命令。

[root@VM_96_242_centos ~]# export HISTCONTROL=ignorespace 
[root@VM_96_242_centos ~]# ls -ltr
total 168
-rw-r--r-- 1 root root  5520 Dec 25  2014 install.log.syslog
-rw-r--r-- 1 root root 12754 Dec 25  2014 install.log
-rw------- 1 root root  2005 Dec 25  2014 anaconda-ks.cfg
-rw-r--r-- 1 root root    12 Dec  9 21:11 a.txt

[root@VM_96_242_centos ~]# pwd

[root@VM_96_242_centos ~]#   service mysqld start   (注意這條命令的最前面是一個空格)
而後咱們來查看歷史記錄
[root@VM_96_242_centos ~]# history |tail -3
  844  2016-12-12 17:01:55 ls -ltr
  845  2016-12-12 17:01:59 pwd
  846  2016-12-12 17:02:36 history |tail -3

是否是發現咱們剛剛執行的,service mysqld start 沒有了
注意:若是不想讓歷史記錄記住哪條命令,直接在執行命令的時候,添加空格就能夠。

固然哪天你想清空全部歷史命令能夠執行:
[root@VM_96_242_centos ~]# history -c    //清空全部記錄
[root@VM_96_242_centos ~]# history         //查看是否被清空
    1  2016-12-12 17:12:12 history mysql

相關文章
相關標籤/搜索