我使用的是 Ubuntu 23.10 x64。该time程序有一个 -f 标志,但当我运行时它说-f找不到命令。
time -f "%Uu %Ss %er %MkB %C" ./countwords hamlet.txt
Run Code Online (Sandbox Code Playgroud)
我试图让time程序除了默认输出之外还输出内存使用情况。
您可能正在运行bash(或zsh),它有自己的time内置命令,以便它可以对整个管道进行计时,而不仅仅是单个命令:
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]\nRun Code Online (Sandbox Code Playgroud)\n您可以看到内置time命令只有一个可选-p标志。
如果您想使用如图所示的外部time命令 ( ) ,则需要显式指定它:/usr/bin/timeman time
command time -f '%Uu %Ss %er %MkB %C' ./countwords hamlet.txt\nRun Code Online (Sandbox Code Playgroud)\n