zsh 是如何存储历史的?历史文件格式
How zsh stores history? History file format
我不确定我是否完全理解 zsh 如何存储它的历史记录。示例行:
: 1458291931:0;ls -l
我想我们在这里:
- 时间戳:1458291931
- 命令:ls -l
但是中间这个神秘的 0 是什么意思?
这就是所谓的*扩展历史记录格式,由EXTENDED_HISTORY
shell option. The second number (the "mystical 0") is the duration of the command. "0" either means that the command finished quickly or - depending on your settings - that the duration is not saved. If either of the shell options启用INC_APPEND_HISTORY
或SHARE_HISTORY
启用(您可以通过setopt | grep -E '^(incappend|share)history$'
查看), 那么 zsh
会在确认命令后立即将历史条目写入历史文件。在这种情况下,持续时间将保存为“0”。
如果您想在 shell 会话期间使用持续时间指标同时仍将历史记录保存到文件中,您可以设置选项 INC_APPEND_HISTORY_TIME
,在这种情况下 zsh
将在写入条目之前等待命令完成。显然,否则这将表现得像 INC_APPEND_HISTORY
.
注意:只有 INC_APPEND_HISTORY
、INC_APPEND_HISTORY_TIME
和 SHARE_HISTORY
选项中的一个应该处于活动状态
我不确定我是否完全理解 zsh 如何存储它的历史记录。示例行:
: 1458291931:0;ls -l
我想我们在这里:
- 时间戳:1458291931
- 命令:ls -l
但是中间这个神秘的 0 是什么意思?
这就是所谓的*扩展历史记录格式,由EXTENDED_HISTORY
shell option. The second number (the "mystical 0") is the duration of the command. "0" either means that the command finished quickly or - depending on your settings - that the duration is not saved. If either of the shell options启用INC_APPEND_HISTORY
或SHARE_HISTORY
启用(您可以通过setopt | grep -E '^(incappend|share)history$'
查看), 那么 zsh
会在确认命令后立即将历史条目写入历史文件。在这种情况下,持续时间将保存为“0”。
如果您想在 shell 会话期间使用持续时间指标同时仍将历史记录保存到文件中,您可以设置选项 INC_APPEND_HISTORY_TIME
,在这种情况下 zsh
将在写入条目之前等待命令完成。显然,否则这将表现得像 INC_APPEND_HISTORY
.
注意:只有 INC_APPEND_HISTORY
、INC_APPEND_HISTORY_TIME
和 SHARE_HISTORY
选项中的一个应该处于活动状态