Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中是否可以使用纳秒的strftime?_Bash_Unix_Posix_Strftime - Fatal编程技术网

在bash中是否可以使用纳秒的strftime?

在bash中是否可以使用纳秒的strftime?,bash,unix,posix,strftime,Bash,Unix,Posix,Strftime,在bash中,有没有办法通过strftime获得纳秒级的Unix时间 我的unix时间行: <command> | awk '{ print strftime("%s"), $0; }' | awk'{print strftime(“%s”),$0;} 我无法使用日期+%N,因为日期只计算一次 有什么解决办法吗?您仍然可以使用date ls | xargs -IQ date "+%s.%N Q" 只是输出中没有%s。。。(但你也可以解决这个问题)我发现一个解决方法是使用wh

在bash中,有没有办法通过strftime获得纳秒级的Unix时间

我的unix时间行:

<command> |  awk '{ print strftime("%s"),  $0; }'
| awk'{print strftime(“%s”),$0;}
我无法使用日期+%N,因为日期只计算一次


有什么解决办法吗?

您仍然可以使用
date

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

只是输出中没有%s。。。(但你也可以解决这个问题)

我发现一个解决方法是使用while read。日期以这种方式更新。不需要时间

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

在GNU/Linux和V>=4.2下,您可以在纯bash中使用
proc/timerlist
,请参阅示例和他的示例,我不认为
xargs
是长时间运行命令的好解决方案。根据手册页:“当您使用-I选项时,从输入读取的每一行都会在内部缓冲。”实际上,这意味着
xargs
在整个命令完成之前不会执行
date
。因此,如果您试图为守护进程或长时间运行的命令的输出添加时间戳,
xargs
将不会有太大帮助。我想您可以通过不使用
-I
并让
xargs
围绕
date
执行包装来解决这个问题,但是对于bash中的一个简单任务来说,这是一个非常麻烦的问题。