Xha*_*Liu 4 unix shell time profiling io-redirection
我想知道程序运行了多长时间,所以我尝试了"/ usr/bin/time ./program>/dev/null".但很快我发现它显示程序的输出到stderr.我尝试了"/ usr/bin/time ./program>/dev/null 2>&1",但是/ usr/bin/time的输出没有出现.所以我的问题是,如何忽略程序的输出,并保持时间的输出.
非常感谢.
使用该-o标志将输出从时间发送到其他地方stderr.例如,如果您仍想在屏幕上显示它:
/usr/bin/time -o /dev/tty ./program >/dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)
或者,如果你想要stdout非常糟糕的输出:
/usr/bin/time sh -c './program >/dev/null 2>&1'
Run Code Online (Sandbox Code Playgroud)
或类似的.但是,现在您还要测量shell启动过程的时间,这可能是也可能不是问题.