无法读取 Zsh 历史的时间戳 [英] Unable to read the timestamp of Zsh history

查看:63
本文介绍了无法读取 Zsh 历史的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:理解以下时间戳

1241036430

在 ~/.history

at ~/.history

: 1241036336:0;vim ~/.zshrc
: 1241036379:0;vim ~/bin/HideTopBar
: 1241036421:0;ls
: 1241036430:0;cat ~/.history

当我有

setopt EXTENDED_HISTORY
HISTFILE=~/.history

在 .zshrc 中.

in .zshrc.

如何读取时间戳?

推荐答案

这个简单的util,称为 localtime 是读取带有时间戳的文件的黄金:

This simple util, called localtime is gold for reading files with timestamps:

#!/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"
}

  • (还有一点演示文稿 :))

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

    It handles lots of cases, and seem to understand both timestamps in seconds and mini-seconds, etc.

    $ localtime < ~/.histfile
    <snip>
    : Sat Sep 17 05:55:17 2016:0;cat localtime
    

    这篇关于无法读取 Zsh 历史的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆