如何查看命令执行的时间?

Man*_*nde 9 bash command-history timestamps

history执行命令时,它显示最近执行的命令的列表。是否有任何规定可以让我们看到执行这些特定命令的时间?

dam*_*ois 17

您需要设置HISTTIMEFORMATenv 变量。

来自help history

If the $HISTTIMEFORMAT 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 displayed history entry.  No time stamps are printed otherwise.
Run Code Online (Sandbox Code Playgroud)

strftime 联机帮助页中描述了该格式。

请参阅此处此处的示例。最有用的可能是

$ export HISTTIMEFORMAT='%F %T '
$ history|tail -2
501  2014-11-03 20:51:41 export HISTTIMEFORMAT='%F %T '
502  2014-11-03 20:51:44 history
Run Code Online (Sandbox Code Playgroud)

  • 尝试从链接中添加更多信息。 (2认同)