是否可以ts
打印相对于二进制文件启动时间的时间戳,而不是挂钟时间?我通常用它来测量单个命令运行中事件之间所花费的时间,因此挂钟时间并不是很有趣;相对时间,主要是命令开始运行的时间。获得相同行为的其他解决方案也受到赞赏。
例如some --command=or 'something' | ts '%.T'
答案1
至少与moreutils
实施时,有一个-s
选项:
If the -i or -s switch is passed, ts timestamps incrementally instead. In case of -i, every timestamp will be the time elapsed since the last timestamp. In case of -s, the time elapsed since start of the program is used. The default format changes to "%H:%M:%S", and "%.S" and "%.s" can be used as well.
前任。
$ while : ; do printf '...\n'; sleep 1; done | ts
May 11 15:42:41 ...
May 11 15:42:42 ...
May 11 15:42:43 ...
May 11 15:42:44 ...
^C
但
$ while : ; do printf '...\n'; sleep 1; done | ts -s
00:00:00 ...
00:00:01 ...
00:00:02 ...
00:00:03 ...
00:00:04 ...
^C