.zshrc
在 macOS 上,我在与命令行历史记录相关的文件中使用这些选项:
# History is appended after completion of each command and with extended information: timestamp and duration.
# This means the history is saved in chronological order (of command completion time).
# However, the history is not shared, so each terminal has its own history while it is open.
setopt INC_APPEND_HISTORY_TIME
# Keep more entries in memory and in .zsh_history file.
HISTSIZE=10000
SAVEHIST=5000
# When trimming history file, keep unique commands and trim duplicates first.
setopt HIST_EXPIRE_DUPS_FIRST
# Do not enter a command into the history if it is a duplicate of the previous event.
setopt HIST_IGNORE_DUPS
这工作得很好,如果我运行这两个命令......
% sleep 1
% sleep 2
…我现在可以看到执行时间以及历史记录中花费的时间:
% history -DE -2
5056 21.11.2020 23:13 0:01 sleep 1
5057 21.11.2020 23:14 0:02 sleep 2
但是,查看该.zsh_history
文件仅显示命令,而没有时间戳和执行时间的痕迹。
% tail -3 .zsh_history
sleep 1
sleep 2
history -DE -2
发送它hexdump -C
不会泄露任何秘密字符:
% tail -4 .zsh_history | hexdump -C
00000000 73 6c 65 65 70 20 31 0a 73 6c 65 65 70 20 32 0a |sleep 1.sleep 2.|
00000010 68 69 73 74 6f 72 79 20 2d 44 45 20 2d 32 0a 74 |history -DE -2.t|
00000020 61 69 6c 20 2d 33 20 2e 7a 73 68 5f 68 69 73 74 |ail -3 .zsh_hist|
00000030 6f 72 79 0a |ory.|
00000034
有人知道zsh
这些信息存储在哪里吗?
答案1
除了内存之外,它不会将此信息存储在任何地方。至少,除非您还添加
setopt EXTENDED_HISTORY
到你的~/.zshrc
文件。然后它会将它们永久写入您的$HISTFILE
.
(setopt SHARE_HISTORY
也会将此信息写入您的,但只是暂时的。当您退出 shell 时,$HISTFILE
它将删除您的所有时间信息。)$HISTFILE