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