I'm on Ubuntu.

Running time seems to output its result to something other than STDOUT or STDERR. Here's why I think so:

[siminm@amide ~]$ time echo hi
hi

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi >/dev/null 

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi 2>/dev/null 
hi

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi 2>&1 >/dev/null 

real    0m0.000s
user    0m0.000s
sys 0m0.000s
[siminm@amide ~]$ time echo hi &>/dev/null 

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

HOWEVER

[siminm@amide ~]$ /usr/bin/time echo hi 2>/dev/null 
hi
link|improve this question

71% accept rate
feedback

3 Answers

up vote 2 down vote accepted

Your shell, which is probably bash, provides a builtin command time. There is also a separate program called time in /usr/bin/, which is in your $PATH. The behavior of the two is different. If you want consistency across all configurations, you should use the program /usr/bin/time instead of the bash builtin time.

link|improve this answer
When I run which time it returns /usr/bin/time – Mikhail Apr 29 '11 at 20:43
@Mikhail, what does type -a time tell you? – glenn jackman Apr 29 '11 at 23:22
@glenn, time is a shell keyword time is /usr/bin/time -- this is rather self explanatory now. thanks! – Mikhail Apr 30 '11 at 23:26
feedback

You are always only redirecting the output of your command. Since time writes to stderr try the following:

(time ls >> /stdout/output/of/ls 2>> /stderr/output/of/ls) 2>> /output/of/time
link|improve this answer
This is great! I had no idea you can wrap functions in parenthesis like that – Mikhail Apr 30 '11 at 23:27
feedback

"time" builtin output goes to what stderr points to before redirections do happen.

Any non builtin command like /usr/bin/time cannot override the redirection as they happen before it is launched so its output goes to stderr.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.