无法读取Zsh历史记录的时间戳

Léo*_* 준영 16 timestamp zsh

问题:了解以下时间戳

1241036430
Run Code Online (Sandbox Code Playgroud)

在〜/ .history

: 1241036336:0;vim ~/.zshrc
: 1241036379:0;vim ~/bin/HideTopBar
: 1241036421:0;ls
: 1241036430:0;cat ~/.history
Run Code Online (Sandbox Code Playgroud)

当我有

setopt EXTENDED_HISTORY
HISTFILE=~/.history
Run Code Online (Sandbox Code Playgroud)

在.zshrc中.

你怎么看时间戳?

Nic*_*ley 19

试试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
Run Code Online (Sandbox Code Playgroud)

  • 如果这不起作用,请检查`history`是别名的(我的是`fc -l 1`,它不会采取任何进一步的选项).zsh`history`内置调用`fc -l`,你可以使用上面的选项:`fc -l -d`,例如. (5认同)
  • 不适合我,我如何在OS X中执行此操作? (2认同)

Sio*_*osm 12

您可以使用从zsh邮件列表中的答案中获取的单行显示人类可读时间戳的整个历史记录:

perl -lne 'm#: (\d+):\d+;(.+)# && printf "%s :: %s\n",scalar localtime $1,$2' $HISTFILE
Run Code Online (Sandbox Code Playgroud)

我建议将输出管道传输到寻呼机(less例如)以使其更具可读性.


ole*_*enb 3

这个简单的util称为localtimeis gold,用于读取带有时间戳的文件:

#!/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"
}
Run Code Online (Sandbox Code Playgroud)
  • (还有一个小介绍:))

它处理很多情况,并且似乎理解以秒和小秒为单位的时间戳等。

$ localtime < ~/.histfile
<snip>
: Sat Sep 17 05:55:17 2016:0;cat localtime
Run Code Online (Sandbox Code Playgroud)