如何格式化“时间”输出

Lea*_*cim 3 bash time

我使用的是 Ubuntu 23.10 x64。该time程序有一个 -f 标志,但当我运行时它说-f找不到命令。

time -f "%Uu %Ss %er %MkB %C" ./countwords hamlet.txt
Run Code Online (Sandbox Code Playgroud)

我试图让time程序除了默认输出之外还输出内存使用情况。

roa*_*ima 6

您可能正在运行bash(或zsh),它有自己的time内置命令,以便它可以对整个管道进行计时,而不仅仅是单个命令:

\n
type time\n  time is a shell keyword\n\nhelp time\n  time: time [-p] pipeline\n      Report time consumed by pipeline's execution.\n      [\xe2\x80\xa6]\n
Run Code Online (Sandbox Code Playgroud)\n

您可以看到内置time命令只有一个可选-p标志。

\n

如果您想使用如图所示的外部time命令 ( ) ,则需要显式指定它:/usr/bin/timeman time

\n
command time -f '%Uu %Ss %er %MkB %C' ./countwords hamlet.txt\n
Run Code Online (Sandbox Code Playgroud)\n