在命令行敲命令的时候,会习惯性按方向键的“上”键,来减少重复的命令输入。
但有一天发现,按“上”键之后,发现命令并不是之前敲击的命令,而是很久之前敲击的命令。
根据这个现象,怀疑是history出现问题。手动查看history,然后执行history -w ,history -a 然后将~/.bash_history文件备份cp ~/.bash_history{,.bak}
然后执行history -C 清除history,然后敲击命令,发现,会出现命令会有一句没一句的记录在history中,并不是所有的命令都记录。
history 这个是bash中的一个命令,如果执行which history的话,不会有任何输出。
[root@localhost ~]# ls -l /etc/profile
-rw-r--r-- 1 root root 1044 11月 1 09:38 /etc/profile
[root@localhost ~]# ls -l ~/.bashrc
-rw-r--r-- 1 root root 3748 11月 1 09:38 /etc/.bashrc
[root@localhost ~]# ls -l ~/.bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
[root@localhost ~]# lsattr /etc/profile
-------------e-- /etc/profile
[root@localhost ~]# lsattr ~/.bashrc
-------------e-- /root/.bashrc
[root@localhost ~]# lsattr ~/.bash_profile
-------------e-- /root/.bash_profile
[root@localhost ~]# getfacl /etc/profile
getfacl: Removing leading '/' from absolute path names
# file: etc/profile
# owner: root
# group: root
user::rw-
group::r--
other::r--
[root@localhost ~]# getfacl ~/.bashrc
getfacl: Removing leading '/' from absolute path names
# file: root/.bashrc
# owner: root
# group: root
user::rw-
group::r--
other::r--
[root@localhost ~]# getfacl ~/.bash_profile
getfacl: Removing leading '/' from absolute path names
# file: root/.bash_profile
# owner: root
# group: root
user::rw-
group::r--
other::r--
[root@localhost ~]# env | grep -i hist
HISTSIZE=1000 ## 只要不是HISTSIZE=0,那么history就是开启状态
HISTCONTROL=ignoredups
[root@localhost ~]# shopt | grep -i hist
cmdhist on
histappend on ### 开启追加模式
histreedit off
histverify off
lithist off
syslog_history off ### 不用诧异,这里默认就是off
如果上述的内容都确认了,那么只能通过重新安装bash包来恢复history问题了
[root@localhost ~]# rpm -ql bash | grep history
/usr/share/man/man1/history.1.gz
[root@localhost ~]# rpm -qa | grep bash
bash-4.2.46-34.uelc20.x86_64
bash-completion-2.1-8.uelc20.noarch
重新安装
yum reinstall bash-4.2.46-34.uelc20.x86_64