开发者

Is strftime with nanoseconds possible in bash?

开发者 https://www.devze.com 2023-01-10 05:10 出处:网络
Is there any way to obtain Unix Time with nanoseconds with strftime in bash? My line for unix time : <command> |awk \'{ print strftime(\"%s\"),$0; }\'

Is there any way to obtain Unix Time with nanoseconds with strftime in bash?

My line for unix time :

<command> |  awk '{ print strftime("%s"),  $0; }'

I cannot use date +%N because date is only evaluated once.

Is there any work aroun开发者_运维知识库d?


I found a workaround using while read. date gets updated that way. No need for strftime.

<command> |  while read line; do d=`date +%s%N`; echo $d $line; done


You could still use date

ls | xargs -IQ date "+%s.%N Q"

Just do not have % in your output... (but you can work around that too)

0

精彩评论

暂无评论...
验证码 换一张
取 消