有没有一种方法来重定向输出时间在Linux中的文件 [英] Is there a way to redirect time output to file in Linux

查看:445
本文介绍了有没有一种方法来重定向输出时间在Linux中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚想在Linux上定时程序有点问题:时间命令允许
测量程序的执行时间:

Just a little question about timing programs on Linux: the time command allows to measure the execution time of a program:

[ed@lbox200 ~]$ time sleep 1

real    0m1.004s
user    0m0.000s
sys     0m0.004s

工作正常。但是,如果我尝试输出重定向到一个文件,它失败。

Which works fine. But if I try to redirect the output to a file, it fails.

[ed@lbox200 ~]$ time sleep 1 > time.txt

real    0m1.004s
user    0m0.001s
sys     0m0.004s

[ed@lbox200 ~]$ cat time.txt 
[ed@lbox200 ~]$ 

我知道有时间的其他实现的选项-o写一个文件,但
我的问题是关于没有这些选项的命令。

I know there are other implementations of time with the option -o to write a file but my question is about the command without those options.

有什么建议?

推荐答案

尝试

{ time sleep 1 ; } 2> time.txt

它结合了时间和STDERR您的命令到TIME.TXT

which combines the STDERR of "time" and your command into time.txt

或者使用

{ time sleep 1 2> sleep.stderr ; } 2> time.txt

从时间把STDERR从睡眠到文件sleep.stderr,只有STDERR进入TIME.TXT

which puts STDERR from "sleep" into the file "sleep.stderr" and only STDERR from "time" goes into "time.txt"

这篇关于有没有一种方法来重定向输出时间在Linux中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆