在bash中,所执行的命令可以用history显示出来,但是bash的机制是:先将命令写入baffer,退出shell时才会写入.bash_history文件中,所以最后.bash_history文件中的命令无法分辨出来时间,解决这个问题可以采用时间戳的方法。
bash中提供了时间戳的参数HISTTIMEFORMAT
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each history entry displayed by the history builtin. If this variable is set, time stamps are written to the history file so they may be pre-served across shell sessions.
|
有了这个参数,可以让执行的命令用history显示时,前面加上时间戳。举例如下:
1008 2009-10-14 14:31:00 history
1009 2009-10-14 14:32:23 cat .bash_profile
1010 2009-10-14 14:36:01 man bash
1011 2009-10-14 14:37:53 history
|
另外就是需要让bash实时写入历史命令。这也有相关参数:
export PROMPT_COMMAND="history -a" #用以实时写入history
export HISTTIMEFORMAT="%F %T " #history带时间戳
|
阅读(1135) | 评论(0) | 转发(0) |