shell - 如何重定向 "time"命令的输出?

标签 shell unix time io-redirection

我尝试重定向 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/

相关文章:

shell - screen 环境中的 tqdm 打印新行和未知字符

linux - 如何知道当前季度的日期?

c - C 代码在 Minix 系统上运行的进程数

linux - 为什么我的 Erlang 引导脚本可以在控制台运行,但在从 init 系统(sysvinit、upstart、systemd)运行时却不起作用?

在 C 中创建具有停止、启动功能的守护进程

python - 如何在 python 中初始化 time() 对象

excel - 在 Excel 中将分钟和秒转换为小时、分钟和秒

shell - 将 Cygwin PID 转换为 Windows PID

bash - 在 shell 脚本中添加第一个命令问题的答案

在特定时间执行的 PHP 脚本