How can I redirect the output of the “time” command?

前端 未结 7 1538
甜味超标
甜味超标 2020-11-30 19:19

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
7条回答
  •  心在旅途
    2020-11-30 19:21

    The command time sends it's output to STDERR (instead of STDOUT). That's because the command executed with time normally (in this case ls) outputs to STDOUT.

    If you want to capture the output of time, then type:

    (time ls) 2> filename
    

    That captures only the output of time, but the output of ls goes normal to the console. If you want to capture both in one file, type:

    (time ls) &> filename
    

    2> redirects STDERR, &> redirects both.

提交回复
热议问题