Shell历史记录文件的格式是什么 [英] What is the format of shell history files
问题描述
我的~/.zsh_history
显示:
: 1449561637:0;echo "foobar"
我猜想它会变成unix timestamp
:
exit code
;
command
,但是时间戳和第一个冒号之前的空间如何?
I'm guessing it goes unix timestamp
:
exit code
;
command
but what about the space before the timestamp and first colon?
有正式的规格吗?
推荐答案
如注释中所述,历史文件的格式取决于shell,有时甚至取决于shell的特定设置.
As already noted in the comments, the format of the history file depends on the shell and sometimes even on specific settings of the shell.
在您的情况下,您正在启用EXTENDED_HISTORY
选项的情况下使用zsh
(通过显式设置或使用csh
-仿真).根据 ZSH手册,具有EXTENDED_HISTORY
的历史记录条目的格式为如下:
In your case you are using zsh
with the EXTENDED_HISTORY
option enabled (either by explicitly setting it or by using csh
-emulation). According to the ZSH manual the format of history entries with EXTENDED_HISTORY
is as follows:
: <beginning time>:<elapsed seconds>;<command>
因此,时间戳之前的空格只是格式的一部分,第二个冒号和分号之间的数字实际上是命令所花费的时间,而不是退出代码.
So the space before the timestamp is just part of the format and the number between the second colon an the semicolon is actually the time taken by the command and not the exit code.
注意:如果设置了INC_APPEND_HISTORY
选项,则<elapsed seconds>
将始终为0
,因为这样,在输入命令后,历史记录条目将立即写入文件中.如果要记录持续时间并继续在Shell会话之间共享历史记录,则可能要改用INC_APPEND_HISTORY_TIME
.该命令仅在命令完成后才写入历史文件.
Note: <elapsed seconds>
will always be 0
, if the INC_APPEND_HISTORY
option is set, because then the history entry is written to the file immediately after entering the command. If you want to log the duration and keep sharing the history between shell sessions, you may want to use INC_APPEND_HISTORY_TIME
instead. This writes to the history file only after the command completed.
这篇关于Shell历史记录文件的格式是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!