zshはタイムスタンプと実行時間をどこに保存しますか?

zshはタイムスタンプと実行時間をどこに保存しますか?

.zshrcmacOSでは、コマンドライン履歴に関連するファイルに次のオプションを使用します。

# 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

これら2つのコマンドを実行すると正常に動作します...

% 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この情報はあなたの情報にも記録されますが、一時的にのみ記録されます。シェルを終了すると、$HISTFILEすべての時間情報が削除されます。)$HISTFILE

おすすめ記事