質問
問題:次のタイムスタンプを理解する
1241036430
〜/ .history
で: 1241036336:0;vim ~/.zshrc
: 1241036379:0;vim ~/bin/HideTopBar
: 1241036421:0;ls
: 1241036430:0;cat ~/.history
持っているとき
setopt EXTENDED_HISTORY
HISTFILE=~/.history
.zshrcで。
タイムスタンプの読み方
解決
この単純な util はlocaltime
と呼ばれ、読むのに最適です。タイムスタンプ付きのファイル:
#!/usr/bin/perl
# http://perl.plover.com/classes/mybin/samples/source/localtime
if ($ARGV[0] eq '-f') {
*show_localtime = \&show_localtime_list;
shift;
}
if (@ARGV) {
for (@ARGV) {
print show_localtime($_), "\n";
}
} else {
while (<>) {
s/^(\d+)/show_localtime($1)/e;
print;
}
}
sub show_localtime {
my $t = shift;
scalar localtime $t;
}
sub show_localtime_list {
my $t = shift;
my @a = localtime $t;
"@a\n"
}
- (プレゼンテーション:))
多くのケースを処理し、秒単位のタイムスタンプとミニ秒などの両方を理解しているようです
$ localtime < ~/.histfile
<snip>
: Sat Sep 17 05:55:17 2016:0;cat localtime
他のヒント
history -d
をお試しください。または、単にhistory -
と入力してcontrol-Dを押すと、さまざまなオプションがすべて表示されます。
% history -
-D -- print elapsed times
-E -- dd.mm.yyyy format time-stamps
-d -- print time-stamps
-f -- mm/dd/yyyy format time-stamps
-i -- yyyy-mm-dd format time-stamps
-m -- treat first argument as a pattern
-n -- suppress line numbers
-r -- reverse order of the commands
上の回答から取得したこのワンライナーを使用して、人間が読み取れるタイムスタンプで履歴全体を表示できます。 zshメーリングリスト:
perl -lne 'm#: (\d+):\d+;(.+)# && printf "%s :: %s\n",scalar localtime $1,$2' $HISTFILE
読みやすくするために、出力をページャー(たとえばless
)にパイプすることをお勧めします。
補遺:history
コマンド自体を使用して、保存された履歴ファイルで見つかったタイムスタンプを翻訳することもできます:
Nicholas Rileyが説明したhistory -d < historyfile
コマンドのオプションは、保存された履歴ファイルにも適用されるため、zsh
(または他のオプション)はタイムスタンプを適切に変換します。
これは、複数の履歴ファイルを使用している場合に便利です-1つのptyにつき1つの履歴ファイルを保持するように<=>を設定して、同じシステムで並行して実行されているシェル各ウィンドウ/画面/ ...は特定のタスクに固有であるため、通常の使用から発生する履歴は最終的にテーマに基づいています)。
: 1241036430:0;cat ~/.history
‘: <beginning time>:<elapsed seconds>;<command>’.
extendedhistory-時間を秒単位で保存します。開始時間はエポックからです。
source: http://zsh.sourceforge.net/Doc/ Release / Options.html#index-EXTENDEDHISTORY