码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【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
  • 相关阅读:
    python集合的应用场景
    力扣(LeetCode)901. 股票价格跨度(C语言)
    微软默默给 curl 捐赠一万美元,半年后才通知
    【算法刷题】【反转链表】给定一个单链表的头结点pHead(该头节点是有值的,比如在下图,它的val是1),长度为n,反转该链表后,返回新链表的表头。
    华为云云耀云服务器L实例评测|企业项目最佳实践之华为云介绍(二)
    打造千万级流量秒杀第十八课 热更新:如何解决程序升级中的稳定性问题?
    企业在海外部署服务器后,国内如何稳定访问?
    【Node.js】Node.js入门(六):Express中间件函数
    如何备份 WordPress 数据库
    【微服务】微服务之Feign 与 Ribbon
  • 原文地址:https://blog.csdn.net/imliuqun123/article/details/127813926
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号