ts
可用于将时间添加到文本行的前面:
$ echo "foo bar test" | ts
Dec 06 12:42:16 foo bar test
我想获得这个精确的时间格式,但包括年份,
2014 Dec 06 12:42:16 foo bar test
我怎样才能做到这一点?
答案1
来自手册页:
The optional format parameter controls how the timestamp is formatted,
as used by strftime(3). The default format is "%b %d %H:%M:%S". In
addition to the regular strftime conversion specifications, "%.S" and
"%.s" are like "%S" and "%s", but provide subsecond resolution (ie,
"30.00001" and "1301682593.00001").
例如:
$ echo a | ts '%F %T'
2014-12-06 23:16:02 a
对于请求的特定格式:
$ echo a | ts '%Y %h %d %H:%M:%S'
2014 Dec 06 23:17:40 a
咨询man strftime
对于可用的各种格式说明符。