问题:了解以下时间戳
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)
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例如)以使其更具可读性.
这个简单的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)