CentOS 7 history显示命令操作记录的时间和用户身份

 

centos7中,history命令中不显示操作命令的时间和用户身份

解决该问题只需要在/etc/profile中添加如下变量即可:

设置环境变量

export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S `whoami` "

刷新环境变量

然后运行source /etc/profile命令即可,注意引号中的空格

 

history命令输出结果格式完美解决,如果要清除历史记录,可以运用history -c,具体history用法如下:

history命令的用法及参数usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]

参数:

n :数字,要列出最近的若干命令列表

-c :将目前的 shell 中的所有 history 内容全部消除

-a :将目前新增的 history 指令新增入 histfiles 中,若没有加 histfiles ,则预设写入 ~/.bash_history

-r :将 histfiles 的内容读到目前这个 shell 的 history 记忆中

-w :将目前的 history 记忆内容写入 histfiles

 

 

posted on 2023-05-05 09:32  大兄弟666  阅读(457)  评论(0编辑  收藏  举报