在项目中为防止恶意人员可能获取到历史命令信息,需要修改history的记录数量。

  • HISTSIZE

    • 用于定义 history 命令输出的记录数,默认1000
  • HISTFILESIZE

    • 用于定义在用户家目录下 ~/.bash_history 文件中保存命令记录的总数,默认1000
  • HISTTIMEFORMAT

    • 用于定义~/.bash_history中的记录格式
[root@localhost ~]# echo $HISTSIZE
1000
[root@localhost ~]# echo $HISTFILESIZE
1000

修改配置

设置时间格式

编辑/etc/profile文件,在其中新增或修改HISTTIMEFORMAT参数。

[root@localhost ~]# vi /etc/profile
HISTTIMEFORMAT='<%F %T> : '
[root@localhost ~]# source  /etc/profile
[root@localhost  ~]# history 
  626  <2022-11-30 17:04:07> : source  /etc/profile
  627  <2022-11-30 17:04:09> : history 
  628  <2022-11-30 17:04:39> : vi /etc/profile
  629  <2022-11-30 17:04:45> : source  /etc/profile
  630  <2022-11-30 17:04:47> : history
修改命令输出数

编辑/etc/profile文件,在其中新增或修改HISTSIZE参数。

[root@localhost ~]# vi /etc/profile
HISTSIZE=5
[root@localhost ~]# source /etc/profile
修改文件记录数

编辑/etc/profile文件,在其中新增或修改HISTFILESIZE参数。

[root@localhost ~]# vi /etc/profile
HISTFILESIZE=5
[root@localhost ~]# source /etc/profile
END

本文标题:修改history命令SIZE参数配置

本文作者:宇宙最帅的男人

本文链接:https://lolicp.com/linux/202230477.html

版权声明:转载或者引用本文内容请注明来源及原作者,本文著作权归作者 (宇宙最帅的男人) 所有。

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

最后修改:2022 年 11 月 30 日
如果觉得我的文章对你有用,请随意赞赏