关于Linux上的计时程序的一个小问题:time命令允许测量程序的执行时间:
[ed@lbox200 ~]$ time sleep 1
real 0m1.004s
user 0m0.000s
sys 0m0.004s
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.但是如果我尝试将输出重定向到文件,它就会失败.
[ed@lbox200 ~]$ time sleep 1 > time.txt
real 0m1.004s
user 0m0.001s
sys 0m0.004s
[ed@lbox200 ~]$ cat time.txt
[ed@lbox200 ~]$
Run Code Online (Sandbox Code Playgroud)
我知道还有其他的时间实现,使用-o选项来编写文件,但我的问题是关于没有这些选项的命令.
有什么建议 ?
我正在运行这样的命令:
mycmd1 | mycmd2 | mycmd3 | lp
Run Code Online (Sandbox Code Playgroud)
有没有办法将stderr重定向到整个管道的文件,而不是为每个命令重复它?
也就是说,我宁愿避免这样做:
mycmd1 2>/myfile | mycmd2 2>/myfile | mycmd3 2>/myfile | lp 2>/myfile
Run Code Online (Sandbox Code Playgroud)