• Linux中历史命令


    历史命令,即之前登录session会话中的在命令行键入的命令。

    在Linux中可以有两种方式查询历史命令

    • history命令
    • 当前用户目录中的隐藏文件.bash_history

    一.history

    作用域

    1. 当前登录用户
    2. 之前登录会话和当前登录会话

    意思即: history查询的是当前登录用户在当前会话session和之前登录会话中所键入的命令。

    history工作原理
    Linux维护一份历史命令内存缓存,当前session键入的命令写入这份缓存中,当前用户登录的时候,将.bash_history中记录的历史命令载入缓存。

    [lxy@localhost ~]$ history
    1  su - root
    2  ps -aux|grep tserver
    3  cd /opt/server/tserver
    4  cd Bin/
    5  cd tserver
    6  tail -f log/hplugin/tserver_plugin_hik.log 
    7  tail -f log/cluster.log
    8  less log/cluster.log
    9  cd ..
    

    history有很多参数,这里只介绍下-c参数。 -c:用于清除history的内存缓存,但是并不删除.bash_history中历史命令。

    二.查看.bash_history

    [hik@HikvisionOS ~]$ cat ~/.bash_history
    su - root
    ps -aux|grep tda
    cd /opt/hikserver/tda
    cd Bin/
    cd tda
    tail -f log/hplugin/tda_plugin_hik.log 
    tail -f log/cluster.log
    less log/cluster.log
    cd ..
    

    配置记录历史命令条数

    在“/etc/profile”配置文件中可以配置是否记录历史操作命令。
    vi /etc/profile

    HOSTNAME=`/usr/bin/hostname 2>/dev/null`
    HISTSIZE=1000
    

    修改其中HISTSIZE大小,即可改变记录历史命令的大小。如果改成0,则表示不记录历史命令。默认是1000条

  • 相关阅读:
    二分法细节
    回溯总结
    质数统计查找 厄拉多塞筛
    串联字串比较
    Gitee FUCK U!
    大佬们都说简单而我暴力超时的dp题目
    UML建模工具Astah Pro 8破解教程2022最新最详细版
    r81259.007.01.tarcentos7驱动修改版
    综合案例注册页面
    html链接
  • 原文地址:https://www.cnblogs.com/lxyit/p/9149612.html
Copyright © 2020-2023  润新知