我尝试重定向 time 命令的输出,但我做不到:
$time ls > filename
real 0m0.000s
user 0m0.000s
sys 0m0.000s
在该文件中,我可以看到 ls
命令的输出,而不是 time
命令的输出。
请解释一下为什么我不能以及如何做到这一点。
最佳答案
无需启动子 shell。使用代码块也可以。
{ time ls; } 2> out.txt
或
{ time ls > /dev/null 2>&1 ; } 2> out.txt
关于shell - 如何重定向 "time"命令的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2408981/