Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I tried to redirect the output of the time command, but I couldn't:

$time ls > filename
real    0m0.000s
user    0m0.000s
sys     0m0.000s

In the file I can see the output of the ls command, not that of time. Please explain, why I couldn't and how to do this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
737 views
Welcome To Ask or Share your Answers For Others

1 Answer

no need to launch sub shell. Use a code block will do as well.

{ time ls; } 2> out.txt

or

{ time ls > /dev/null 2>&1 ; } 2> out.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...