让Linux的history命令显示用户名和时间

修改/etc/profile

增加

export HISTTIMEFORMAT="%Y%m%d_%T `whoami` `who am i|awk '{print $1,$5}'|sed 's/ (/@/'|sed 's/)//'` "
export PROMPT_COMMAND='history 1|{ read x y; echo $y; } >> /var/log/.history/${LOGNAME}.history'

之后

mkdir /var/log/.history
source /etc/profile

即可

效果:

 1003  20191227_10:01:45 root [email protected] history
 1004  20191227_10:01:57 root [email protected] source /etc/profile
 1005  20191227_10:02:13 root [email protected] mkdir /var/log/.history
 1006  20191227_10:02:19 root [email protected] source /etc/profile
 1007  20191227_10:02:22 root [email protected] history

猜你喜欢

转载自www.cnblogs.com/zepc007/p/12113461.html