• 【Linux】history有问题,看这篇文章就够了!


    history 记录问题,随机记录内容–已解决

    现象:

    命令行敲命令的时候,会习惯性按方向键的“上”键,来减少重复的命令输入。

    但有一天发现,按“上”键之后,发现命令并不是之前敲击的命令,而是很久之前敲击的命令。

    根据这个现象,怀疑是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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    查看文件的lsattr
    [root@localhost ~]# lsattr /etc/profile
    -------------e-- /etc/profile
    [root@localhost ~]# lsattr ~/.bashrc 
    -------------e-- /root/.bashrc
    [root@localhost ~]# lsattr ~/.bash_profile 
    -------------e-- /root/.bash_profile
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    查看文件的getfacl
    [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--
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    history 相关配置
    是否开启history
    [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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    如果上述的内容都确认了,那么只能通过重新安装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 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    redis我记不住的那些命令(七)
    MySQL 8.2 Command Line Client打开时一闪而过闪退问题
    设计模式——访问者模式(Visitor Pattern)+ Spring相关源码
    提取多个txt数据并合成excel——例子:与中国建交的国家
    数据分析-费米问题
    nginx静态网站部署
    百度10年架构师分享的(Java TCP/IP Socket编程开发经验)看完受益匪浅!
    【OpenCV--视频文件相关操作】
    机器视觉——找到物块中心点
    前端面试:原型和原型链
  • 原文地址:https://blog.csdn.net/imliuqun123/article/details/127813926