linux查看历史操作记录并且显示执行时间 | 您所在的位置:网站首页 › linux查看所有脚本 › linux查看历史操作记录并且显示执行时间 |
使用HISTTIMEFORMAT变量来指定命令中增加时间戳
[root@localhost ~]# export HISTTIMEFORMAT="%F %T " # #注意: 在调用history命令时,行号 然后是HISTTIMEFORMAT的执行结果,然后是命令,注意%T后面有空格。 [root@localhost ~]# history | tail 991 2019-12-08 17:26:33 ls 992 2019-12-08 17:26:33 cd .. 993 2019-12-08 17:26:33 ;s 994 2019-12-08 17:26:33 ls 995 2019-12-08 17:26:33 cd lib 996 2019-12-08 17:26:33 ls 997 2019-12-08 17:26:33 su - postgresql 998 2019-12-08 17:26:33 su - postgres 999 2019-12-08 17:40:24 export HISTTIMEFORMAT="%F %T " 1000 2019-12-08 17:40:31 history | tail [root@localhost ~]#可以将这个变量加入到/etc/profile全局变量设置中,就对所有的会话都生效了 [root@testvm01 ~]# tail /etc/profile else . "$i" >/dev/null 2>&1 fi fi done unset i unset -f pathmunge export HISTTIMEFORMAT="%F %T `who am i` " [root@testvm01 ~]# source /etc/profile备注:这样的话,对于后续登录的会话都是生效的。 疑问:在这里我就有个疑问了,为啥时间格式是%F %T呢,也找了半天,后来在bing上搜索了一个贴,里面提到,HISTTIMEFORMAT使用的是strftime函数的时间格式。 Linux查看具体历史命令 # history | grep zabbixecho ‘export HISTTIMEFORMAT="%F %T whoami "’ >> /etc/profile 注销,重新登录 993 2017-08-11 05:07:14 root exit 994 2017-08-11 04:47:21 root w 参考链接 : https://blog.csdn.net/weixin_34194317/article/details/93424072 history 命令添加时间戳 : https://www.jianshu.com/p/23e0632f1873 |
CopyRight 2018-2019 实验室设备网 版权所有 |