Linux 中 如何将time命令输出的时间信息保存在文件中

 

001、 通常做法

[root@localhost test]# time seq 10 > a.txt 2> xxx     ## 完全追加至xxx

real    0m0.002s
user    0m0.000s
sys     0m0.002s
[root@localhost test]# ls
a.txt  xxx
[root@localhost test]# cat a.txt
1
2
3
4
5
6
7
8
9
10
[root@localhost test]# cat xxx    ## 无内容

 

002、正确做法

[root@localhost test]# ls
[root@localhost test]# time (seq 10 > a.txt) 2> xxx     ## time作用命令用括号括起来,后边在重定向
[root@localhost test]# ls
a.txt  xxx
[root@localhost test]# cat a.txt
1
2
3
4
5
6
7
8
9
10
[root@localhost test]# cat xxx

real    0m0.001s
user    0m0.000s
sys     0m0.001s

 。

下边也可以:

 。

 

posted @ 2025-01-27 13:28  小鲨鱼2018  阅读(106)  评论(0)    收藏  举报