有时候为了服务器安全,防止别人窥探我们输入的命令,我们可以清空历史记录,而更多的时候,我们选择的是在输入特殊命令时候,强制历史记录不记住该命令。

         实验方法:先执行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 

[root@VM_96_242_centos ~]#

系统安全不容小觑,每周一到周五,我们都将分享不同分类的技术视频,只有你想不到,没有做不到。

更多内容请关注:xinsz08    ,你的发是我们前进的动力。

更全更详细的内容,我们在运维开发社群等你!集合最强的凝聚力,做最有生产力的事。