文章目录
一、需求说明二、配置步骤1、临时显示操作时间2、永久设置三、补充说明1、HISTFILESIZE和HISTSIZE2、显示命令执行用户3、格式化输出参数配置4、历史命令保存位置一、需求说明
系统运维工作中我们有时候需要查看历史命令,可以通过history命令查看,此命令只有序号后操作命令。如果是排查问题的时候我们可能还想知道命令执行操作时间、操作用户、操作IP等。
二、配置步骤
1、临时显示操作时间
[root@test1 ~]# export HISTTIMEFORMAT="[%F-%T]"
[root@test1 ~]# history |more
1 [-08-24-11:44:40]hostnamectl set-hostname test1
2 [-08-24-11:44:40]ip addr
3 [-08-24-11:44:40]cd /etc/sysconfig/network-scripts/
4 [-08-24-11:44:40]ll
5 [-08-24-11:44:40]vim ifcfg-ens33
6 [-08-24-11:44:40]reboot
7 [-08-24-11:44:40]ifconfig virbr0 down
8 [-08-24-11:44:40]brctl delbr virbr0
…
2、永久设置
编辑环境变量使环境变量生效[root@test1 ~]# vim /etc/profile
查看效果[root@test1 ~]# source /etc/profile