下面介绍如何为命令行历史记录添加时间。
进入/etc/profile.d
# cd /etc/profile.d/
新建文件custom_history_format.sh
在文件中添加:
export HISTTIMEFORMAT="%Y%m%d %T "
查看效果
# source /etc/profile.d/custom_history_format.sh
# history
596 20170304 22:28:19 mysql -v
597 20170304 22:32:10 which mysqldump
598 20170304 22:36:19 ifconfig
599 20170304 22:37:19 exit
600 20170304 22:38:19 ifconfig
另外,history只能查看当前用户的命令历史记录,例如root用户只能查看root用户的记录,deploy用户只能查看deploy用户的记录。