Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question
add comment

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.

share|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
add comment

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
share|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
add comment

"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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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