time <command>在 bash 中的格式:
$time ./test.sh
real 0m0.000s
user 0m0.006s
sys 0m0.000s
Run Code Online (Sandbox Code Playgroud)
在 zsh 中:
$time ./test.sh
./test.sh 0.01s user 0.00s system 94% cpu 0.007 total
Run Code Online (Sandbox Code Playgroud)
当我切换到 zsh 时,这总是困扰着我。如何使timein zsh的输出像 bash 一样?
Kus*_*nda 13
所述time关键字zsh产生由变量指定的格式输出TIMEFMT。
这个变量的默认值是
%J %U user %S system %P cpu %*E total
Run Code Online (Sandbox Code Playgroud)
您可以像这样更改它,例如:
TIMEFMT=$'%J\n%U user\n%S system\n%P cpu\n%*E total'
Run Code Online (Sandbox Code Playgroud)
(这实际上只是在默认格式字符串中插入了几个换行符)
这给出了以下类型的输出:
%J %U user %S system %P cpu %*E total
Run Code Online (Sandbox Code Playgroud)
或者,更接近于bash:
TIMEFMT=$'%J\n%U user\n%S system\n%P cpu\n%*E total'
Run Code Online (Sandbox Code Playgroud)
请参阅手册中TIMEFMT变量的文档zshparam。
在我的系统上(运行 zsh 5.7.1),这显示
$ time sleep 2
sleep 2
0.00s user
0.00s system
0% cpu
2.010 total
Run Code Online (Sandbox Code Playgroud)